mysql实例部署
mysql多实例部署
[root@YL src]# ls
mysql-5.7.39-linux-glibc2.12-x86_64
mysql-5.7.39-linu-x-glibc2.12-x86_64.tar.gz
配置用户和组并解压二进制程序到/usr/local目录下
[root@YL src]# groupadd -r mysql
[root@YL src]# useradd -M -s /sbin/nologin -g mysql mysq
[root@YL src]# mv mysql-5.7.39-linux-glibc2.12-x86_64 /usr/local/
[root@YL src]# ls /usr/local/
mysql-5.7.39-linux-glibc2.12-x86_64 src
修改/usr/local/mysql的属主属组
[root@YL local]# chown -R mysql.mysql /usr/local/mysql
[root@YL local]# ll /usr/local/mysql -d
lrwxrwxrwx. 1 mysql mysql 36 Jul 31 13:22 /usr/local/mysql -> mysql-5.7.39-linux-glibc2.12-x86_64/
配置环境变量
[root@YL local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@YL local]# . /etc/profile.d/mysql.sh
[root@YL local]# echo $PATH
/usr/local/mysql/bin:/usr/local/httpd/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
创建各实例存放的目录
[root@YL ~]# mkdir -p /opt/data/{3306,3307,3308}
[root@YL ~]# chown -R mysql.mysql /opt/data/
[root@YL ~]# tree /opt/data/
/opt/data/
├── 3306
├── 3307
└── 3308
初始化各实例
[root@YL ~]# mysqld --initialize --datadir=/opt/data/3306 --user=mysql
2022-07-31T06:33:10.327132Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (s
...........
2022-07-31T06:33:11.099591Z 1 [Note] A temporary password is generated for root@localhost: Yh54TldQiJ_y
[root@YL ~]# mysqld --initialize --datadir=/opt/data/3307 --user=mysql
2022-07-31T06:33:10.327132Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (s
...........
2022-07-31T06:33:11.099591Z 1 [Note] A temporary password is generated for root@localhost: ?PFw>:KTJ7Lv
[root@YL ~]# mysqld --initialize --datadir=/opt/data/3308 --user=mysql
2022-07-31T06:33:10.327132Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (s
...........
2022-07-31T06:33:11.099591Z 1 [Note] A temporary password is generated for root@localhost: O0&9_Rl7LTkT
配置/etc/my.cnf配置文件
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
[mysqld3306]
datadir = /opt/data/3306
port = 3306
socket = /tmp/mysql3306.sock
pid-file = /opt/data/3306/mysql_3306.pid
log-error=/var/log/3306.log
[mysqld3307]
datadir = /opt/data/3307
port = 3307
socket = /tmp/mysql3307.sock
pid-file = /opt/data/3307/mysql_3306.pid
log-error=/var/log/3307.log
[mysqld3308]
datadir = /opt/data/3308
port = 3308
socket = /tmp/mysql3308.sock
pid-file = /opt/data/3308/mysql_3306.pid
log-error=/var/log/3308.log
启动各实例
// 将3308,7,6加入到systemctl服务中
[root@YL ~]# cat /usr/lib/systemd/system/3308.service
[Unit]
Description=3308 server daemon
After=network.target sshd-keygen.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/bin/mysqld_multi start 3308
ExecStop=ps -ef |grep 3308 |grep -v grep | awk '{print$2}' | xargs kill -9
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
[root@YL ~]# systemctl start 3306
[root@YL ~]# systemctl start 3307
[root@YL ~]# systemctl start 3308
[root@YL ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 80 *:3307 *:*
LISTEN 0 80 *:3308 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
初始化密码
[root@YL ~]# mysql -uroot -p'Yh54TldQiJ_y' -S /tmp/mysql3306.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.39
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> set password = password ('liuyang123!');
Query OK, 0 rows affected, 1 warning (0.00 sec)
[root@YL ~]# mysql -uroot -p'?PFw>:KTJ7Lv' -S /tmp/mysql3307.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.39
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> set password = password('liuyang123!');
Query OK, 0 rows affected, 1 warning (0.00 sec)
[root@YL ~]# mysql -uroot -p'O0&9_Rl7LTkT' -S /tmp/mysql3308.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.39
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> set password = password('liuyang123!');
Query OK, 0 rows affected, 1 warning (0.00 sec)

浙公网安备 33010602011771号