🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 安装MySQL 8.0.12 参考文档: [CentOS 上 编译MySQL-5.7.x 或者 MySQL-8.0 源码 及 多实例安装](https://my.oschina.net/u/3147971/blog/913920) [CENTOS6.6下mysql5.7.11带boost和不带boost的源码安装](https://www.cnblogs.com/galengao/p/5755788.html) [CentOS7.4 源码安装MySQL8.0](https://www.cnblogs.com/chenqs/p/8911670.html) ### 下载MySQL源码包 MySQL官网下载页: ~~~ https://www.mysql.com/downloads/ ~~~ 在列表最下面,找到MySQL社区版(MySQL Community Edition)的链接,点进去。 :-: ![](https://box.kancloud.cn/7e9640fa3b037d2d1db24bc83d19a672_355x78.jpg) 按下图选择: :-: ![](https://box.kancloud.cn/20580fce66c9315003a74196e828ee70_1168x505.jpg) 这里有两个源码包可供选择,一个是带boost的,一个不带boost。如果选择不带boost库的,你还是要自己安装boost库。我们选择带boost库的,一起安装比较方便。 点击“下载”,进入下载页 :-: ![](https://box.kancloud.cn/7f3040983253ef5c7a9fa92d759219fa_1144x70.jpg) 不需要登录,直接点击页面下面的“No thanks, just start my download.”即可获取下载链接 :-: ![](https://box.kancloud.cn/e4a01ec6a90fcc17573057eb3760603f_981x602.jpg) 获取到的下载链接是: ~~~ https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.12.tar.gz ~~~ 使用wget下载到packages目录下,并解包 ~~~ [root@localhost packages]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.12.tar.gz [root@localhost packages]# tar zxf mysql-boost-8.0.12.tar.gz [root@localhost packages]# cd mysql-8.0.12 [root@localhost mysql-8.0.12]# ~~~ 创建用户和组: ~~~ [root@localhost mysql-8.0.12]# groupadd mysql [root@localhost mysql-8.0.12]# useradd -g mysql mysql ~~~ 安装依赖: ~~~ [root@localhost mysql-8.0.12]# yum install ncurses-devel -y [root@localhost mysql-8.0.12]# yum install libaio -y [root@localhost mysql-8.0.12]# yum install glibc-devel.i686 glibc-devel -y [root@localhost mysql-8.0.12]# yum install gcc gcc-c++ -y [root@localhost mysql-8.0.12]# yum install cmake -y ~~~ 编译MySQL ~~~ [root@localhost mysql-8.0.12]# cmake -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=boost [root@localhost mysql-8.0.12]# make [root@localhost mysql-8.0.12]# make install ~~~ 这里要编译很久……………… ……………… 终于编译完了,应该没什么问题。 配置MySQL。这里配置数据目录、日志目录、unix_socket目录、tmp目录等 ~~~ [root@localhost mysql-8.0.12]# mkdir -p /data/mysql [root@localhost mysql-8.0.12]# cd /data/mysql [root@localhost mysql]# mkdir data [root@localhost mysql]# mkdir log [root@localhost mysql]# mkdir socket [root@localhost mysql]# mkdir tmp [root@localhost mysql]# mkdir binlog [root@localhost mysql]# mkdir run [root@localhost mysql]# cd .. [root@localhost data]# chown -R mysql.mysql ./mysql/ [root@localhost data]# chown -R mysql.mysql /usr/local/mysql/ ~~~ 导出mysql路径: ~~~ [root@localhost data]# vim /etc/profile ~~~ 添加如下内容: ~~~ MYSQL_HOME=/usr/local/mysql/bin PATH=$PATH:$MYSQL_HOME export PATH MYSQL_HOME ~~~ 加载profile ~~~ [root@localhost data]# source /etc/profile ~~~ 编辑MySQL配置文件,一定要小心各种文件的路径,错了启动不了的。 ~~~ [root@localhost data]# cp /etc/my.cnf /etc/my.cnf.bak [root@localhost data]# vim /etc/my.cnf ~~~ 写入内容如下: ~~~ [client] socket=/data/mysql/socket/mysql.sock [mysqld] basedir=/usr/local/mysql datadir=/data/mysql/data socket=/data/mysql/socket/mysql.sock tmpdir=/data/mysql/tmp pid_file=/data/mysql/run/mysql.pid log_error=/data/mysql/log/error.log log_bin=/data/mysql/binlog/mysql-bin slow_query_log_file=/data/mysql/log/slow-query.log # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/var/log/mariadb.log pid-file=/var/run/mariadb.pid log-error=/data/mysql/log/error.log # # include all files from the config directory # !includedir /etc/my.cnf.d ~~~ 编辑其它配置文件 ~~~ [root@localhost data]# vim /etc/my.cnf.d/mysql-clients.cnf ~~~ 写入如下内容: ~~~ [mysql] no_auto_rehash [mysql_upgrade] [mysqladmin] [mysqlbinlog] [mysqlcheck] [mysqldump] [mysqlimport] [mysqlshow] [mysqlslap] ~~~ 这是简化版的配置文件,如果需要完整版的,可以度娘一下。 初始化数据目录和SSL ~~~ [root@localhost data]# /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data [root@localhost data]# /usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data ~~~ 这一步很重要,会在你指定的目录初始化MySQL的数据文件和root账号密码。初始化数据目录后,root账号初始密码会输出在/data/mysql/log/error.log中,等一下要登录MySQL并修改为自己的密码。 配置MySQL服务 ~~~ [root@localhost data]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql ~~~ 修改如下配置并保存: ~~~ basedir=/usr/local/mysql datadir=/data/mysql/data mysqld_pid_file_path=/data/mysql/run/mysql.pid ~~~ 继续 ~~~ [root@localhost data]# chkconfig --add mysql [root@localhost data]# chkconfig mysql on [root@localhost data]# service mysql start [root@localhost data]# service mysql stop [root@localhost data]# systemctl start mysql.service [root@localhost data]# systemctl status mysql.service ~~~ 绿色的active (running)很好看吧。 修改root账号的密码 ~~~ [root@localhost data]# mysql -uroot -p 输入初始密码,登录mysql。初始密码在/data/mysql/log/error.log中 登录后修改密码,否则什么也干不了的。 mysql> alter user 'root'@'localhost' identified by '123456'; mysql> quit; ~~~ MySQL安装完毕。