MySql教程

mysql多实例部署

本文主要是介绍mysql多实例部署,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

目录
  • mysql多实例部署

mysql多实例部署

软件下载

[root@localhost src]# ls
debug  kernels  mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz

创建用户

[root@localhost src]# useradd -r -M -s /sbin/nologin mysql

[root@localhost src]# id mysql
uid=994(mysql) gid=991(mysql) groups=991(mysql)

解压软件至/usr/local/

[root@localhost src]# tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

做软链接

[root@localhost ~]# cd /usr/local/

[root@localhost local]# ln -sv mysql-5.7.37-linux-glibc2.12-x86_64/ mysql
'mysql' -> 'mysql-5.7.37-linux-glibc2.12-x86_64/'

修改目录/usr/local/mysql的属主属组


[root@localhost local]# chown -R mysql.mysql mysql*
[root@localhost local]# ll
lrwxrwxrwx. 1 mysql mysql  36 Jul 28 23:47 mysql -> mysql-5.7.37-linux-glibc2.12-x86_64/
drwxr-xr-x. 9 mysql mysql 129 Jul 28 23:43 mysql-5.7.37-linux-glibc2.12-x86_64


配置环境变量

[root@localhost local]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh
[root@localhost local]# source /etc/profile.d/mysql.sh 

include文件

[root@localhost mysql]# ln -s /usr/local/mysql/include/ /usr/include/mysql

lib文件

[root@localhost mysql]# vim /etc/ld.so.conf.d/mysql.dnf
/usr/local/mysql/lib/
[root@localhost mysql]# ldconfig 

man文件

[root@localhost mysql]# vim /etc/man_db.conf
MANDATORY_MANPATH                       /usr/man
MANDATORY_MANPATH                       /usr/share/man
MANDATORY_MANPATH                       /usr/local/share/man
MANDATORY_MANPATH                       /usr/local/mysql/man

创建各实例数据存放的目录

[root@localhost mysql]# mkdir -p /opt/data/{3306,3307,3308}
[root@localhost mysql]# ls /opt/data/
3306  3307  3308

更改属主属组

[root@localhost ~]# chown -R mysql.mysql /opt/data/
[root@localhost ~]# ll /opt/data/
total 0
drwxr-xr-x. 2 mysql mysql 6 Jul 28 23:59 3306
drwxr-xr-x. 2 mysql mysql 6 Jul 28 23:59 3307
drwxr-xr-x. 2 mysql mysql 6 Jul 28 23:59 3308

初始化各实例

[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data/3306
2022-07-28T16:01:29.077016Z 1 [Note] A temporary password is generated for root@localhost: Y+lV!EXMe3=W
[root@localhost ~]# echo 'Y+lV!EXMe3=W' > 3306

[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data/3307
2022-07-28T16:02:16.284993Z 1 [Note] A temporary password is generated for root@localhost: jwMSdMj-A1YO
[root@localhost ~]# echo 'jwMSdMj-A1YO' > 3307

[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data/3308
2022-07-28T16:03:17.438701Z 1 [Note] A temporary password is generated for root@localhost: l26/ESIxWega
[root@localhost ~]# echo 'l26/ESIxWega' > 3308

安装perl

[root@localhost ~]# yum -y install perl

配置配置文件/etc/my.cnf

[root@localhost ~]# vim /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_3307.pid
log-error=/var/log/3307.log

[mysqld3308]
datadir = /opt/data/3308
port = 3308
socket = /tmp/mysql3308.sock
pid-file = /opt/data/3308/mysql_3308.pid
log-error=/var/log/3308.log

启动各实例

[root@localhost ~]# mysqld_multi start 3306
[root@localhost ~]# mysqld_multi start 3307
[root@localhost ~]# mysqld_multi start 3308
[root@localhost ~]# 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                 [::]:22                [::]:*          

初始化密码

[root@localhost ~]# mysql -uroot -p'Y+lV!EXMe3=W' -S /tmp/mysql3306.sock
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[root@localhost ~]# yum install libncurses*
[root@localhost ~]# mysql -uroot -p'Y+lV!EXMe3=W' -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.37

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('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

[root@localhost ~]# mysql -uroot -p'jwMSdMj-A1YO' -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.37

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('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
[root@localhost ~]# mysql -uroot -p'l26/ESIxWega' -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 2
Server version: 5.7.37

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('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

这篇关于mysql多实例部署的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!