我有第二个在端口3307上运行mysqld_multi的mysql实例。如果通过端口连接它,我从第一个实例获取数据库,如连接到3306.如果我通过套接字连接,我从第二个实例获取正确的数据库。我需要第二个实例用于测试环境,所以我需要按端口选择实例和它的存储/ datadir。你能救我吗?
的my.cnf
[mysqld_multi]
mysqld = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin
user = root
password = something
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqld2]
mysqld = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin
socket = /var/lib/mysql2/tmp/mysql2.sock
port = 3307
pid-file = /var/run/mysqld/mysqld2.pid
datadir = /var/lib/mysql2
language = /usr/share/mysql/english
user = mysql
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
systemctl status mysqld
mysqld.service - MySQL Community Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled)
Active: active (running) since Mo 2016-02-08 12:54:40 CET; 24h ago
Process: 6901 ExecStartPost=/usr/bin/mysql-systemd-start post code=exited, status=0/SUCCESS)
Process: 6889 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 6900 (mysqld_safe)
CGroup: /system.slice/mysqld.service
├─6900 /bin/sh /usr/bin/mysqld_safe
└─7062 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
mysqld_multi报告
WARNING: Log file disabled. Maybe directory or file isn't writable?
mysqld_multi log file version 2.16; run: Di Feb 9 13:54:19 2016
Reporting MySQL servers
MySQL server from group: mysqld2 is running
连接到第一个实例
$ mysql -u root -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| portal |
| swfl |
+--------------------+
9 rows in set (0,00 sec)
mysql> SHOW VARIABLES LIKE 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0,00 sec)
按端口连接第二个实例
$ mysql -P 3307 -u root -p
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| portal |
| swfl |
+--------------------+
9 rows in set (0,00 sec)
mysql> SHOW VARIABLES LIKE 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0,00 sec)
通过套接字连接到第二个实例
$ mysql -S /var/lib/mysql2/tmp/mysql2.sock -u root -p
mysql> show variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3307 |
+---------------+-------+
1 row in set (0,00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| tmp |
+--------------------+
4 rows in set (0,00 sec)
服务器
使用MySQL 5.6.25的CentOS 7