部署mysql多个版本,或者多实例,方法基本一致。下面均以glibc包安装mysql5.6,mysql5.7
参考:CentOS7.7下二进制部署MySQL多版本多实例实战
一 环境准备
1.卸载已安装的mysql
[root@jingwh~]# rpm -qa | grep mysql
# 结果如下
mysql-community-common-8.0.18-1.el7.x86_64
mysql-community-client-8.0.18-1.el7.x86_64
mysql-community-libs-8.0.18-1.el7.x86_64
# 使用以下命令依次删除上面的程序
[root@jingwh~]# yum remove mysql-xxx-xxx-
2.删除mysql的配置文件
[root@jingwh~]# find / -name mysql
# 结果如下
/etc/selinux/targeted/active/modules/100/mysql
/usr/lib64/mysql
/usr/share/mysql
/mnt/app/mysql5.7/data/mysql
# 使用 rm -rf 删除相关文件|文件夹
[root@jingwh~]# rm -rf /usr/lib64/mysql
3.删除MariaDB的文件
[root@jingwh~]# rpm -qa | grep mariadb
[root@jingwh~]# rpm -e mariadb-xxx --nodeps
4.删除my.cnf
[root@jingwh~]# rm -fr /etc/my.cfg
二 安装mysql5.6
1.解压软件包
mysql安装有三种方式:
yum 安装
、二进制安装
、源码编译安装
,我们这里以二进制安装mysql
[root@jingwh~]# tar xf mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz
[root@jingwh~]# mv mysql-5.6.46-linux-glibc2.12-x86_64 mysql5.6
2.创建实例配置文件
配置文件位置随意,可根据自己安装的版本起名,如:
/etc/my5.6.cnf
注意:如果需要指定log、socket文件位置,需要手动创建文件夹,如下所示
[client]
port=3316
socket=/mnt/app/mysql5.6/scoket/mysql.sock
[mysqld]
user=mysql
port=3316
basedir=/mnt/app/mysql5.6/mysql56
datadir=/mnt/app/mysql5.6/data
socket=/mnt/app/mysql5.6/scoket/mysql.sock
log-error=/mnt/app/mysql5.6/log/mysql.err
pid-file=/mnt/app/mysql5.6/mysql.pid
character_set_server=utf8mb4
symbolic-links=0
3.创建mysql用户并加入用户组授权
useradd -r -g [用户名] [用户组]
chown -R mysql.mysql [mysql目录]
[root@jingwh~]# useradd -r -g mysql mysql
[root@jingwh~]# chown -R mysql.mysql /mnt/app/mysql5.6
4.初始化
[root@jingwh~]# /mnt/app/mysql5.6/mysql56/scripts/mysql_install_db --user=mysql --basedir=/mnt/app/mysql5.6/mysql56 --datadir=/mnt/app/mysql5.6/data
5.编写systemd启动脚本
[root@jingwh~]# cat > /etc/systemd/system/mysqld3316.service <<EOF
[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=/mnt/app/mysql5.6/mysql56/bin/mysqld --defaults-file=/etc/my5.6.cnf
LimitNOFILE = 5000
EOF
6.启动实例
[root@jingwh~] systemctl daemon-reload
[root@jingwh~] systemctl start mysqld3316.service
[root@jingwh~] netstat -lntup|grep mysqld
7.绝对路径登录MySQL实例
[root@jingwh~] /mnt/app/mysql5.6/mysql56/bin/mysql -S /mnt/app/mysql5.6/scoket/mysql.sock
8.初次登录设置root密码
set password for root@localhost = password('VuKv@GfUijEov^YU');
flush privileges;
三 安装mysql5.7
1.解压软件包
[root@jingwh~]# tar xf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
[root@jingwh~]# mv mysql-5.7.28-linux-glibc2.12-x86_64 mysql5.7
2.创建实例配置文件
配置文件位置随意,可根据自己安装的版本起名,如:
/etc/my5.7.cnf
注意:如果需要指定log、socket文件位置,需要手动创建文件夹,如下所示
[client]
port=3316
socket=/mnt/app/mysql5.7/scoket/mysql.sock
[mysqld]
user=mysql
port=3306
basedir=/mnt/app/mysql5.7/mysql56
datadir=/mnt/app/mysql5.7/data
socket=/mnt/app/mysql5.7/scoket/mysql.sock
log-error=/mnt/app/mysql5.7/log/mysql.err
pid-file=/mnt/app/mysql5.7/mysql.pid
character_set_server=utf8mb4
symbolic-links=0
3.创建mysql用户并加入用户组授权
useradd -r -g [用户名] [用户组]
chown -R mysql.mysql [mysql目录]
[root@jingwh~]# useradd -r -g mysql mysql
[root@jingwh~]# chown -R mysql.mysql /mnt/app/mysql5.7
4.初始化(与5.6不同)
[root@jingwh~]# /mnt/app/mysql5.7/mysql57/bin/mysqld --initialize-insecure --user=mysql --basedir=/mnt/app/mysql5.7/mysql57 --datadir=/mnt/app/mysql5.7/data
5.编写systemd启动脚本
[root@jingwh~]# cat > /etc/systemd/system/mysqld3306.service <<EOF
[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=/mnt/app/mysql5.7/mysql57/bin/mysqld --defaults-file=/etc/my5.7.cnf
LimitNOFILE = 5000
EOF
6.启动实例
[root@jingwh~] systemctl daemon-reload
[root@jingwh~] systemctl start mysqld3306.service
[root@jingwh~] netstat -lntup|grep mysqld
7.绝对路径登录MySQL实例
[root@jingwh~] /mnt/app/mysql5.7/mysql56/bin/mysql -S /mnt/app/mysql5.7/scoket/mysql.sock
8.初次登录设置root密码
set password for root@localhost = password('VuKv@GfUijEov^YU');
flush privileges;
四、常用sql
1.创建用户,授权数据库
use mysql;
create database md_test character set utf8;
grant all privileges on md_test.* to md_test@'%' identified by 'md_test@123456';
网友评论