1安装依赖包
yum install gcc gcc-c++ make cmake libaio-devel openssl-devel zlib-devel ncurses-devel bison -y
2下载解压boost:
mkdir /usr/local/src/boost && cd /usr/local/src/boost
wget -c https://kent.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz --no-check-certificate
3下载mysql-5.6.44源码并解压:
mkdir /usr/local/src/mysql && cd /usr/local/src/mysql
wget -c https://downloads.mysql.com/archives/get/p/23/file/mysql-5.6.44.tar.gz
4进入MySQL解压目录,建立编译目录并进入编译目录:
cd /usr/local/src/mysql/mysql-5.6.44 && mkdir build && cd build
5配置
mkdir /opt/mysql
cmake /usr/local/src/mysql/mysql-5.6.44 -DCMAKE_INSTALL_PREFIX=/opt/mysql -DWITH_BOOST=/usr/local/src/boost/boost_1_59_0
6编译安装
make
make install
7配置启动脚本
cp /opt/mysql/support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql
8配置/etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
event_scheduler = ON
innodb_file_format=barracuda
innodb_large_prefix=on
lower_case_table_names=1
port = 3306
socket = /tmp/mysql.sock
datadir = /opt/mysql/var
9创建mysql用户
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql
chown -R mysql:mysql /opt/mysql //授权读写数据库的权限
chown -R mysql:mysql /tmp //授权读写临时文件的权限
10初始化数据库
/opt/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/opt/mysql --datadir=/opt/mysql/var --user=mysql
11设置环境变量
echo "export PATH=$PATH:/opt/mysql/bin/" >> /etc/profile
source /etc/profile
12设置root用户密码
mysqladmin -u root password 'root'
13登陆数据库,授权远程访问权限
mysql -uroot -proot
(1) root用户使用密码从任何主机连接到mysql服务器:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
(2) 开启root用户远程连接到mysql服务器
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
(3)刷新权限: flush privileges;
14开启访问端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
注意:
1)安装到/opt/mysql下的MySQL数据库程序以及初始化数据,是为了打包完整的程序,方便迁移到干净的CentOS系统中,打包指令:
tar zcvPf mysql-5.6.44.tar.gz /opt/mysql /etc/my.cnf /etc/init.d/mysql
在新操作系统中,指令解压指令可用: tar zxvPf mysql-5.6.44.tar.gz
说明MySQL编译完成之后,不再依赖安装环境,可以静态迁移到相同的操作系统中
参考文献https://www.huaweicloud.com/kunpeng/software/mysql.html
来源:oschina
链接:https://my.oschina.net/u/4302850/blog/4473401