安装依赖
yum install -y gcc gcc-c++ automake autoconf
yum -y install cmake bison-devel ncurses-devel libaio-devel
MysqL-5.6.40二进制包下载地址
https://downloads.MysqL.com/archives/get/file/MysqL-5.6.40-linux-glibc2.12-x86_64.tar.gz
1.下载MysqL-5.6.40二进制包
[[email protected] ~]# wget https://downloads.MysqL.com/archives/get/file/MysqL-5.6.40-linux-glibc2.12-x86_64.tar.gz
2.解压缩MysqL二进制包到/usr/local
[[email protected] ~]# tar xf MysqL-5.6.40-linux-glibc2.12-x86_64.tar.gz -C /usr/local
3.修改名称、做软连接
[[email protected] ~]# cd /usr/local [[email protected] local]# mv MysqL-5.6.40-linux-glibc2.12-x86_64 MysqL-5.6.40 [[email protected] local]# ln -s MysqL-5.6.40 MysqL
4.创建MysqL用户和组
//创建MysqL组
[[email protected] local]# groupadd MysqL
[[email protected] local]# useradd -g MysqL -s /bin/false MysqL
5.拷贝主配置文件
//备份/etc/my.cnf
[[email protected] local]# mv /etc/my.cnf /etc/my.cnf.old
//拷贝主配置文件
[[email protected] ~]# cp /usr/local/MysqL/support-files/my-default.cnf /etc/my.cnf
6.拷贝启动脚本
[[email protected] ~]# cp /usr/local/MysqL/support-files/MysqL.server /etc/init.d/MysqLd
7.初始化MysqL
//进入/usr/local/MysqL/scripts
[[email protected] ~]# cd /usr/local/MysqL/scripts
//初始化前安装依赖包
[[email protected] scripts]# yum -y install autoconf
//初始化MysqL
[[email protected] scripts]# ./MysqL_install_db --user=MysqL --basedir=/usr/local/MysqL --datadir=/usr/local/MysqL/data --user #指定MysqL用户 --basedir #指定MysqL安装目录 --datadir #指定MysqL数据目录
初始化报错
[[email protected] scripts]# ./MysqL_install_db --user=MysqL --basedir=/usr/local/MysqL --datadir=/usr/local/MysqL/data FATAL ERROR: please install the following Perl modules before executing ./MysqL_install_db: Data::Dumper
原因:缺少autoconf依赖包
[[email protected] scripts]# yum -y install autoconf
8.添加MysqL命令环境变量
//导出MysqL命令环境变量
[[email protected] scripts]# echo "export PATH=/usr/local/MysqL/bin:$PATH" > /etc/profile.d/MysqL.sh
//使配置生效
[[email protected] scripts]# source /etc/profile
9.配置systemd管理MysqL
[[email protected] scripts]# vim /etc/systemd/system/MysqLd.service [Unit] Description=MysqL Server Documentation=man:MysqLd(8) Documentation=http://dev.MysqL.com/doc/refman/en/using-systemd.html After=network.target After=syslog.target [Install] WantedBy=multi-user.target [Service] User=MysqL Group=MysqL ExecStart=/usr/local/MysqL/bin/MysqLd --defaults-file=/etc/my.cnf LimitNOFILE = 5000
10.启动MysqL、检查启动
//启动MysqL
[[email protected] scripts]# systemctl start MysqLd ; systemctl enable MysqLd [[email protected] scripts]# netstat -ntpl | grep 3306 tcp6 0 0 :::3306 :::* LISTEN 31349/MysqLd
11.进入MysqL并设置密码
//设置MysqL密码
MysqL> set password=password('123'); Query OK,0 rows affected (0.00 sec) MysqL> flush privileges; Query OK,0 rows affected (0.01 sec)