CentOS7编译安装MySQL8.0.x
环境准备:
centos版本7
[root@bogon ~]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core)
mysql版本8.0.20
[root@bogon src]# ll mysql-8.0.20.tar.gz -rw-r--r--. 1 root root 266282970 May 31 10:47 mysql-8.0.20.tar.gz
卸载之前mysql\mariadb
安装:
一、安装cmake3
yum install epel-release -y yum install cmake3 -y
二、升级gcc
安装devtoolset包 yum install centos-release-scl yum install devtoolset-4 激活gcc版本,使其生效 scl enable devtoolset-4 bash 或 source /opt/rh/devtoolset-4/enable
注意:此方式仅在当前shell生效。若想将mysql安装写入脚本中不要使用scl enable devtoolset-4 bash,使用另一种方式。
三、编译安装mysql
tar xvf mysql-8.0.20.tar.gz mkdir build && cd build cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_BOOST=../boost make -j 4(根据个人cpu核数选择)
四、创建用户及数据目录、启动脚本
groupadd mysql useradd -s /sbin/nologin -M -g mysql mysql mkdir /home/www/mysqldata chown -R mysql:mysql /home/www/mysqldata chgrp -R mysql /usr/local/mysql/.
cp support-files/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
五、初始化mysql并修改密码
/usr/local/mysql/bin/mysqld --initialize-insecure --basedir=/usr/local/mysql --datadir=${MySQL_Data_Dir} --user=mysql
/usr/local/mysql/bin/mysqladmin -u root password password
六、配置环境变量
ln -sf /usr/local/mysql/bin/mysql /usr/bin/mysql ln -sf /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump ln -sf /usr/local/mysql/bin/myisamchk /usr/bin/myisamchk ln -sf /usr/local/mysql/bin/mysqld_safe /usr/bin/mysqld_safe ln -sf /usr/local/mysql/bin/mysqlcheck /usr/bin/mysqlcheck