MySQL8单台机器多实例启动
一、本地环境配置
先安装单个mysql,安装过程请参考CentOS7 安装MySQL8
二、配置第二个实例
进入已安装好的MySQL目录复制一份新的
[root@gone local]# cp mysql mysql2 -R
为当前的安装包添加配置文件
[root@gone local]# vim /etc/my3307.cnf
[mysqld]
basedir=/usr/local/mysql2
datadir=/usr/local/mysql2/data
port=3307
socket=/tmp/mysql3307.sock
mysqlx_port=33070
mysqlx_socket=/tmp/mysqlx33070.sock
进入到mysql2目录执行命令启动mysql
[root@gone mysql2]# bin/mysqld --defaults-file=/etc/my3307.cnf --user=mysql
2023-02-14T08:25:59.967577Z 0 [System] [MY-010116] [Server] /usr/local/mysql2/bin/mysqld (mysqld 8.0.25) starting as process 91886
2023-02-14T08:26:00.090328Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-02-14T08:26:00.729129Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-02-14T08:26:00.858054Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33070, socket: /tmp/mysqlx33070.sock
2023-02-14T08:26:00.905405Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2023-02-14T08:26:00.905871Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2023-02-14T08:26:00.938212Z 0 [System] [MY-010931] [Server] /usr/local/mysql2/bin/mysqld: ready for connections. Version: '8.0.25' socket: '/tmp/mysql3307.sock' port: 3307 MySQL Community Server - GPL
查看是否有端口为3307的mysql服务
[root@gone local]# netstat -an|grep LISTEN
连接mysql 服务验证
[root@gone ~]# mysql -u root -p -S /tmp/mysql3308.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.25 MySQL Community Server - GPL
Copyright (c) 2000, 2021, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.11 sec)
mysql>
停止mysql 服务
[root@gone mysql2]# bin/mysqladmin -u root -p -S /tmp/mysql3307.sock shutdown