centos7.4系统源码编译安装MySQL5.7.31
源码下载地址
https://dev.mysql.com/downloads/mysql/
检测系统
rpm -qa | grep mysql / /查看系统自带mysql
yum -y remove mysql-* //卸载mysql
rpm -e --nodeps mysql-5.1.73-3.el6_5.x86_64 //卸载mysql
安装环境依赖
yum install gcc gcc-c++ ncurses ncurses-devel bison libgcrypt perl cmake
准备boost库
tar -zxvf boost_1_59_0.tar.gz
mv boost_1_59_0 /usr/local/boost
然后创建用户组以及用户
cat /etc/group | grep mysql //查看是否存在mysql用户组
cat /etc/passwd | grep mysql //查看是否存在mysql用户
groupadd mysql //创建用户组
useradd -r -g mysql mysql //创建用户
创建文件目录
mkdir /usr/local/mysql
mkdir /usr/local/mysql/data
mkdir /usr/local/mysql/logs
mkdir /usr/local/mysql/pids
chown -R mysql:mysql /usr/local/mysql //赋予用户组
安装cmake
tar -zxvf cmake-3.6.2.tar.gz
cd cmake-3.6.2
./bootstrap
gmake
make install
查看cmake
解压MySql5.7.31
tar -zxvf mysql-5.7.31.tar.gz
cd mysql-5.7.31
执行Cmake编译安装MySql
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost
这里出现了问题
解决方案
yum -y install ncurses-devel //安装依赖
rm -rf build //删除之前
再次执行cmake,成功
编译安装
make && make install
安装成功
配置配置文件
cd /usr/local/mysql
mkdir etc
cd etc
vim my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[client]
port=3306
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/usr/local/mysql/logs/mysqld.log
pid-file=/usr/local/mysql/pids/mysqld.pid
配置环境变量
vim /etc/profile
export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
source /etc/profile
配置开机自启
cp support-files/mysql.server /etc/init.d/mysqld
chmod a+x /etc/init.d/mysqld //需要root权限
chkconfig mysqld on //开机自启
启动MySQL
//初始化操作 --initialize-insecure 初始密码为空
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
//启动mysql
/etc/init.d/mysqld start
设置密码,配置远程连接
mysql -u root
mysql> use mysql;
mysql>update user set authentication_string=password(‘123456’) where user=‘root’ and Host = ‘localhost’;
mysql> FLUSH PRIVILEGES;
mysql>grant all privileges on . to ‘root’@’%’ identified by ‘123456’ with grant option;
mysql> FLUSH PRIVILEGES;
开放端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload //重启
//查看已开放端口
firewall-cmd --list-ports