• Post author:
  • Post category:mysql
  • Post comments:0评论

1、基础环境准备

[root@db01 ~]# yum remove -y mariadb-libs
[root@db01 ~]# useradd mysql
[root@db01 ~]# mkdir -p /data/app /data/330{6,7}/{data,logs}
[root@db01 ~]# chown -R mysql.mysql /data
[root@db01 ~]# tar xf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz -C /data/app/
[root@db01 ~]# cd /data/app/
[root@db01 app]# ln -s mysql-5.7.28-linux-glibc2.12-x86_64 mysql
[root@db01 ~]# vim /etc/profile     //末尾添加
export PATH=/data/app/mysql/bin:$PATH 
[root@db01 ~]# source /etc/profile

2、初始化数据

[root@db01 ~]# mysqld --initialize-insecure --user=mysql --basedir=/data/app/mysql --datadir=/data/3306/data
[root@db01 ~]# mysqld --initialize-insecure --user=mysql --basedir=/data/app/mysql --datadir=/data/3307/data

3、准备配置文件

[root@db01 ~]# vim /data/3306/my.cnf
[mysqld]
user=mysql 
basedir=/data/app/mysql
datadir=/data/3306/data 
port=3306
socket=/tmp/mysql-1.sock

[root@db01 ~]# vim /data/3307/my.cnf
[mysqld]
user=mysql 
basedir=/data/app/mysql
datadir=/data/3307/data
port=3307
socket=/tmp/mysql-2.sock

4、启动

[root@db01 3306]# mysqld_safe --defaults-file=/data/3306/my.cnf &
[root@db01 3306]# mysqld_safe --defaults-file=/data/3307/my.cnf &
[root@db01 ~]# netstat -ntlp | grep mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      18859/mysqld        
tcp6       0      0 :::3307                 :::*                    LISTEN      19040/mysqld

[root@db01 ~]# mysql -S /tmp/mysql-1.sock
[root@db01 ~]# mysql -S /tmp/mysql-2.sock

5、加入systemd管理

[root@db01 ~]# cd /usr/lib/systemd/system
[root@db01 system]# vim mysqld-1.service 
[Unit]
Description=MySQL Server
After=network.target
After=syslog.target

[Service]
User=mysql
Group=mysql
PIDFile=/data/3306/data/mysqld-1.pid
ExecStart=/data/app/mysql/bin/mysqld --defaults-file=/data/3306/my.cnf
Restart=on-failure
RestartPreventExitStatus=1
TimeoutSec=0
PrivateTmp=false

[Install]
WantedBy=multi-user.target

[root@db01 system]# vim mysqld-2.service 
[Unit]
Description=MySQL Server
After=network.target
After=syslog.target

[Service]
User=mysql
Group=mysql
PIDFile=/data/3307/data/mysqld-2.pid
ExecStart=/data/app/mysql/bin/mysqld --defaults-file=/data/3307/my.cnf
Restart=on-failure
RestartPreventExitStatus=1
TimeoutSec=0
PrivateTmp=false

[Install]
WantedBy=multi-user.target

[root@db01 system]# systemctl daemon-reload
[root@db01 system]# systemctl start mysqld-1
[root@db01 system]# systemctl start mysqld-2
[root@db01 system]# netstat -ntlp | grep mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      9095/mysqld         
tcp6       0      0 :::3307                 :::*                    LISTEN      9131/mysqld 

发表回复

验证码: 98 − 95 =