ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

mysql多实例部署

2022-07-29 00:32:29  阅读:159  来源: 互联网

标签:opt 部署 root 实例 usr mysql local localhost


目录

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)

标签:opt,部署,root,实例,usr,mysql,local,localhost
来源: https://www.cnblogs.com/loronoa/p/16530831.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有