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/'
[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)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。