MySQL多实例部署
配置用户和组并解压二进制程序至/usr/local下
| |
| [root@zzd139 ~] |
| [root@zzd139 ~] |
| uid=994(mysql) gid=991(mysql) groups=991(mysql) |
| |
| |
| [root@zzd139 ~] |
| [root@zzd139 ~] |
| [root@zzd139 local] |
| 'mysql' -> 'mysql-5.7.38-linux-glibc2.12-x86_64/' |
| [root@zzd139 local] |
| total 0 |
| drwxr-xr-x. 2 root root 6 May 19 2020 bin |
| drwxr-xr-x. 2 root root 6 May 19 2020 etc |
| drwxr-xr-x. 2 root root 6 May 19 2020 games |
| drwxr-xr-x. 2 root root 6 May 19 2020 include |
| drwxr-xr-x. 2 root root 6 May 19 2020 lib |
| drwxr-xr-x. 3 root root 17 Jun 28 09:25 lib64 |
| drwxr-xr-x. 2 root root 6 May 19 2020 libexec |
| lrwxrwxrwx. 1 root root 36 Jul 31 12:37 mysql -> mysql-5.7.38-linux-glibc2.12-x86_64/ |
| drwxr-xr-x. 9 root root 129 Jul 31 12:36 mysql-5.7.38-linux-glibc2.12-x86_64 |
| drwxr-xr-x. 2 root root 6 May 19 2020 sbin |
| drwxr-xr-x. 5 root root 49 Jun 28 09:25 share |
| drwxr-xr-x. 2 root root 6 May 19 2020 src |
| |
| |
| [root@zzd139 local] |
| [root@zzd139 local] |
| |
| |
| [root@zzd139 mysql] |
| [root@zzd139 mysql] |
| |
| |
| [root@zzd139 mysql] |
| '/usr/include/mysql' -> '/usr/local/mysql/include/' |
| [root@zzd139 mysql] |
| lrwxrwxrwx. 1 root root 25 Jul 31 12:43 /usr/include/mysql -> /usr/local/mysql/include/ |
| |
| |
| [root@zzd139 mysql] |
| [root@zzd139 mysql] |
| |
| |
| [root@zzd139 mysql] |
| MANDATORY_MANPATH /usr/local/mysql/man |
创建各实例数据存放的目录
| [root@zzd139 ~] |
| [root@zzd139 ~] |
| [root@zzd139 ~] |
| drwxr-xr-x. 3 mysql mysql 18 Jul 31 12:49 /opt/mysql/ |
| [root@zzd139 ~] |
| /opt/mysql/ |
| └── data |
| ├── 3306 |
| ├── 3307 |
| └── 3308 |
| |
| 4 directories, 0 files |
初始化各实例
| |
| [root@zzd139 ~] |
| 2022-07-31T04:57:58.055583Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). |
| 2022-07-31T04:57:58.199632Z 0 [Warning] InnoDB: New log files created, LSN=45790 |
| 2022-07-31T04:57:58.222224Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. |
| 2022-07-31T04:57:58.277486Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 58b0e5f9-108d-11ed-ad61-000c29f177ce. |
| 2022-07-31T04:57:58.278037Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. |
| 2022-07-31T04:57:58.466754Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher. |
| 2022-07-31T04:57:58.466766Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher. |
| 2022-07-31T04:57:58.467085Z 0 [Warning] CA certificate ca.pem is self signed. |
| 2022-07-31T04:57:58.504976Z 1 [Note] A temporary password is generated for root@localhost: Zijiul!dD9ah |
| |
| |
| [root@zzd139 ~] |
| 2022-07-31T04:58:47.248209Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). |
| 2022-07-31T04:58:47.390566Z 0 [Warning] InnoDB: New log files created, LSN=45790 |
| 2022-07-31T04:58:47.411008Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. |
| 2022-07-31T04:58:47.466127Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 76027d4f-108d-11ed-b06a-000c29f177ce. |
| 2022-07-31T04:58:47.466606Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. |
| 2022-07-31T04:58:47.678872Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher. |
| 2022-07-31T04:58:47.678885Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher. |
| 2022-07-31T04:58:47.679220Z 0 [Warning] CA certificate ca.pem is self signed. |
| 2022-07-31T04:58:47.693800Z 1 [Note] A temporary password is generated for root@localhost: sH,POrtex18% |
| |
| |
| [root@zzd139 ~] |
| 2022-07-31T04:59:07.895747Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). |
| 2022-07-31T04:59:08.045977Z 0 [Warning] InnoDB: New log files created, LSN=45790 |
| 2022-07-31T04:59:08.073626Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. |
| 2022-07-31T04:59:08.129126Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 825369bd-108d-11ed-b0c0-000c29f177ce. |
| 2022-07-31T04:59:08.129730Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. |
| 2022-07-31T04:59:08.289922Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher. |
| 2022-07-31T04:59:08.289936Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher. |
| 2022-07-31T04:59:08.290281Z 0 [Warning] CA certificate ca.pem is self signed. |
| 2022-07-31T04:59:08.355936Z 1 [Note] A temporary password is generated for root@localhost: ujU(rICNy1qi |
| |
| |
| [root@zzd139 ~] |
| [root@zzd139 ~] |
| [root@zzd139 ~] |
配置配置文件/etc/my.cnf
| [root@zzd139 ~] |
| [mysqld_multi] |
| mysqld = /usr/local/mysql/bin/mysqld_safe |
| mysqladmin = /usr/local/mysql/bin/mysqladmin |
| |
| [mysqld3306] |
| datadir = /opt/mysql/data/3306 |
| port = 3306 |
| socket = /tmp/mysql3306.sock |
| pid-file = /opt/mysql/data/3306/mysql_3306.pid |
| log-error=/var/log/3306.log |
| |
| [mysqld3307] |
| datadir = /opt/mysql/data/3307 |
| port = 3307 |
| socket = /tmp/mysql3307.sock |
| pid-file = /opt/mysql/data/3307/mysql_3307.pid |
| log-error=/var/log/3307.log |
| |
| [mysqld3308] |
| datadir = /opt/mysql/data/3308 |
| port = 3308 |
| socket = /tmp/mysql3308.sock |
| pid-file = /opt/mysql/data/3308/mysql_3308.pid |
| log-error=/var/log/3308.log |
| [root@zzd139 ~] |
启动实例
| [root@zzd139 ~] |
| [root@zzd139 ~] |
| [root@zzd139 ~] |
| [root@zzd139 ~] |
| [root@zzd139 ~] |
| 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 [::]:* |
登录到mysql修改密码
| [root@zzd139 ~] |
| |
| [root@zzd139 ~] |
| mysql> set password = password('xxxxxx'); |
| Query OK, 0 rows affected, 1 warning (0.00 sec) |
| |
| |
| [root@zzd139 ~] |
| mysql> set password = password('xxxxxx'); |
| Query OK, 0 rows affected, 1 warning (0.00 sec) |
| |
| |
| [root@zzd139 ~] |
| mysql> set password = password('xxxxxx'); |
| Query OK, 0 rows affected, 1 warning (0.00 sec) |
停止实例
| [root@zzd139 ~] |
| [root@zzd139 ~] |
| [root@zzd139 ~] |
| [root@zzd139 ~] |
| 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 128 [::]:22 [::]:* |
使用systemd风格控制实例
| [root@zzd139 system] |
| [root@zzd139 system] |
| [root@zzd139 system] |
| |
| |
| [root@zzd139 system] |
| [Unit] |
| Description=3306 server daemon |
| After=network.target sshd-keygen.target |
| |
| [Service] |
| Type=forking |
| ExecStart=/usr/local/mysql/bin/mysqld_multi start 3306 |
| ExecStop=ps -elf | grep 3306 | grep -v grep | awk -F ' ' '{print $4}' | xargs kill -9 |
| ExecReload=/bin/kill -HUP $MAINPID |
| |
| [Install] |
| WantedBy=multi-user.target |
| |
| [root@zzd139 system] |
| [Unit] |
| Description=3307 server daemon |
| After=network.target sshd-keygen.target |
| |
| [Service] |
| Type=forking |
| ExecStart=/usr/local/mysql/bin/mysqld_multi start 3307 |
| ExecStop=ps -elf | grep 3307 | grep -v grep | awk -F ' ' '{print $4}' | xargs kill -9 |
| ExecReload=/bin/kill -HUP $MAINPID |
| |
| [Install] |
| WantedBy=multi-user.target |
| |
| [root@zzd139 system] |
| [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 -elf | grep 3308 | grep -v grep | awk -F ' ' '{print $4}' | xargs kill -9 |
| ExecReload=/bin/kill -HUP $MAINPID |
| |
| [Install] |
| WantedBy=multi-user.target |
| |
| [root@zzd139 system] |
| [root@zzd139 system] |
| '/usr/bin/my_print_defaults' -> '/usr/local/mysql/bin/my_print_defaults' |
| [root@zzd139 system] |
| [root@zzd139 system] |
| [root@zzd139 system] |
| [root@zzd139 system] |
| 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 [::]:* |
报错信息
| |
| bash: /usr/local/mysql/bin/mysqld_multi: /usr/bin/perl: bad interpreter: No such file or directory |
| |
| |
| [root@zzd139 ~] |
| |
| mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory |
| |
| |
| [root@zzd139 ~] |
| |
| Job for mysql3306.service failed because the control process exited with error code. |
| See "systemctl status mysql3306.service" and "journalctl -xe" for details. |
| |
| |
| [root@zzd139 system] |
| $(找是否有这一行) |
| Jul 31 14:17:54 zzd139 mysqld_multi[17148]: WARNING: my_print_defaults command not found. |
| $(如果有) |
| [root@zzd139 system] |
| '/usr/bin/my_print_defaults' -> '/usr/local/mysql/bin/my_print_defaults' |