MySQL local multiple instances not working

2019-07-08 23:30发布

问题:

So I have MySQL install via homebrew and have edited my.cnf to look like below. I've added mysql and mysql2 directories to /usr/local/var/ which hold the data for the databases and installed a second mysql server configured to use /usr/local/var/mysql2

[mysqld_multi]
mysqld     = /usr/local/Cellar/mysql/5.6.24/bin/mysqld_safe 
mysqladmin = /usr/local/Cellar/mysql/5.6.24/bin/mysqladmin
log        = /var/log/mysqld_multi.log
user       = root
password   = password

[mysqld1]
socket     = /tmp/mysql.sock1
port       = 3306
pid-file   = /usr/local/var/mysql/mysqld1.pid
datadir    = /usr/local/var/mysql/
language   = /usr/local/Cellar/mysql/5.6.24/share/mysql/english
user       = root

[mysqld2]
socket     = /tmp/mysql.sock2
port       = 3308
pid-file   = /usr/local/var/mysql2/mysqld2.pid
datadir    = /usr/local/var/mysql2/
language   = /usr/local/Cellar/mysql/5.6.24/share/mysql/english
user       = root

The problem is that when I start the servers like so:

mysqld_multi start --user=root --password=password

I see that both of them are instantiated when i run

mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running

When I individually start/stop 1/2 both start/stop and in /usr/local/var/mysql the .pid file is generated using my local username not mysqld1.pid and in /usr/local/var/mysql2 there is no .pid file created. I can connect to the database using:

mysql -h 127.0.0.1 -P 3306 -u root -ppassword

However I cannot connect on port 3308

running nmap tells me:

nmap -p 3308 127.0.0.1


Nmap scan report for localhost (127.0.0.1)
Host is up (0.00011s latency).
PORT     STATE  SERVICE
3308/tcp closed unknown

Not sure what is going on here any help would be greatly appraciated.

My_print_defaults have to be executed as follows to produce any output:

my_print_defaults --defaults-file=/usr/local/Cellar/mysql/5.6.24/my.cnf   client mysqld1

--socket=/tmp/mysql.sock1
--port=3306
--pid-file=/usr/local/var/mysql/mysqld1.pid
--datadir=/usr/local/var/mysql/
--language=/usr/local/Cellar/mysql/5.6.24/share/mysql/english
--user=root

my_print_defaults --defaults-file=/usr/local/Cellar/mysql/5.6.24/my.cnf client mysqld2
--socket=/tmp/mysql.sock2
--port=3308
--pid-file=/usr/local/var/mysql2/mysqld2.pid
--datadir=/usr/local/var/mysql2/
--language=/usr/local/Cellar/mysql/5.6.24/share/mysql/english
--user=root
标签: mysql local