操作系统:CentOS Linux release 7.9

实战任务:安装MySQL 5.7.23

操作步骤如下:

1.下载MySQL 5.7.23 : 

 #wget -c http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-boost-5.7.23.tar.gz

2.安装依赖包: 

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

3.解压并创建MySQL组和用户

#tar -zxvf  mysql-boost-5.7.23.tar.gz  

#groupadd mysql

#useradd -r -g mysql -s /bin/false mysql

3.开始编译MySQL 

  #cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/db/data -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8  -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DWITH_BOOST=boost -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DWITH_EMBEDDED_SERVER=1

[root@Linux db]# cat /proc/cpuinfo| grep "processor"| wc -l

8

# make -j 8  && make install #并行编译

4.初始化数据库

[root@Linux mysql-5.7.23]#mkdir /db/data

[root@Linux mysql-5.7.23]#chown -R mysql:mysql /db/data

[root@Linux mysql-5.7.23]#/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql  --datadir=/db/data

[root@Linux mysql-5.7.23]# cp /usr/local/mysql/support-files/mysql.service /etc/init.d/msyqld

[root@Linux mysql-5.7.23]# chmod 755 /etc/init.d/mysqld

[root@Linux mysql-5.7.23]# chkcofnig --add mysqld

[root@Linux mysql-5.7.23]# chkconfig mysqld on

[root@Linux mysql-5.7.23]#servcie mysqld start

5.配置my.cnf文件

[root@Linux mysql-5.7.23]# vi /etc/my.cnf

explicit_defaults_for_timestamp=true

basedir=/usr/local/mysql

datadir=/db/data

socket=/tmp/mysqld.sock

symbolic-links=0

log-error=/var/log/mysqld.log

 user=mysql

 6.配置MySQL启动脚本

[root@Linux mysql-5.7.23]#cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld

[root@Linux mysql-5.7.23]# chmod 755 /etc/init.d/mysqld

[root@Linux mysql-5.7.23]# chkconfig --add mysqldroot@Linux mysql-5.7.23]# service mysqld start

Starting MySQL.. ERROR! The server quit without updating PID file (/db/data/Linux.pid).

[root@Linux db]# ps -aux|grep mysql

root     20495  0.0  2.0 1797788 164308 ?      Sl   1月31   0:42 mysqld -uroot

root     22312  0.0  0.0 112824   980 pts/0    S+   17:21   0:00 grep --color=auto mysql

[root@Linux db]# kill 20495

[root@Linux db]# service mysqld start

Starting MySQL. SUCCESS!

[root@Linux db]# mysql –uroot

mysql> SET PASSWORD=PASSWORD('*******') ;#设置密码

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

7.配置环境变量

[root@Linux db]# vi /etc/profile

PATH=/usr/local/mysql/bin:$PATH

export PATH

[root@Linux db]# source /etc/profile