MySQL5.7源码部署


源码安装MySQL5.7

1.安装依赖:

# yum -y install ncurses ncurses-devel openssl-devel bison gcc gcc-c++ make cmake

下载MySQL:

wget  https://repo.huaweicloud.com/mysql/Downloads/MySQL-5.7/mysql-5.7.35.tar.gz               (华为镜像站)

还需安装boost包:

# wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz            

安装MySQL:

# groupadd mysql
# useradd -r -g mysql -s /bin/false mysql
# tar xvf mysql-5.7.19.tar.gz
注意目录权限
# cd mysql-5.7.19
[root@mysql3 mysql-5.7.19]# pwd
/root/mysql-5.7.19
[root@mysql3 mysql-5.7.19]# tar xf boost_1_59_0.tar.gz     (注意包的位置)

2.配置

[root@mysql-5.7.17 ~]#

cmake . \
-DWITH_BOOST=boost_1_59_0/ \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DINSTALL_MANDIR=/usr/share/man \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1

常见错误  

       -DWITH_BOOST=boost_1_59_0
  如果没有提前准备,可以使用下面的参数自己装。
  -DDOWNLOAD_BOOST=1
  -DWITH_READLINE=1 \ 5.6被移除
  如果cmake失败,请将CMakeCache.txt缓存移除

 

3.编译安装:

# make       
# make install

初始化:

# cd /usr/local/mysql
# mkdir mysql-files
# chown -R mysql.mysql .
注意目录名称 # bin
/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 保存临时密码。(或者skip-grant-tables) x/dwiQ2<l:hb # bin/mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data

创建日志目录及pid目录
mkdir -p /var/log/mysql
chown -R mysql:mysql /var/log/mysql
mkdir -p /var/lib/mysql
chown -R mysql:mysql /var/lib/mysql
建立MySQL配置文件my.cnf
# vim
/etc/my.cnf [root@mysql1 mysql]# vim /etc/my.cnf [mysqld] basedir=/usr/local/mysql datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock
pid=/var/lib/mysql/mysql.pid
log-error=/var/log/mysql/mysql.log
[client]
port=3306
socket=/var/lib/mysql/mysql.sock

4.启动MySQL:

vim /usr/lib/systemd/system/mysql.service
[Unit]
Description=mysql
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecReload=/usr/local/mysql/support-files/mysql.server restart
ExecStop=/usr/local/mysql/support-files/mysql.server stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target

 设置环境变量:

echo 'PATH=$PATH':/usr/local/mysql/bin >> /etc/profile
source  /etc/profile

CentOS6:

# chkconfig --add mysqld       添加mysql服务
# chkconfig mysqld on           开机自动启动mysql服务
# service mysqld start          

CentOS7:

#systemctl    start   mysqld        

#systemctl    enable   mysqld      
查看mysql进程
# ps aux |grep mysqld 首次登陆需要密码   # mysql -u root -p '密码' 登陆有问题吗? # /usr/local/mysql/bin/mysql -u root -p'x/dwiQ2<l:hb'   不要忘了配置新密码。 # /usr/local/mysql/bin/mysqladmin -u root -p 'x/dwiQ2<l:hb' password 'Qing@123'   show databases; 看到库即可。

 

posted @ 2020-07-29 13:52  Noleaf  阅读(676)  评论(0编辑  收藏  举报