Question

I would like to create second mysqld instance.

How can I create a second socket file?

I tried copying /var/run/mysqld/mysqld.sock and create an empty file mysqld2.sock but no luck.

Was it helpful?

Solution

You will want to use mysqld_multi, which is part of a typical MySQL server install. On my Ubuntu server, it was located at /usr/bin/mysqld_multi.

MySQL's Documentation on mysqld_multi

Here is a how to, I used to set up mysqld_multi: MySQL Multi How to

Update, running a 2nd instance from the shell

Start another mysqld using a different, port, socket and data directory

# make a new data directory
mkdir /var/lib/mysql2

# give ownership to mysql user
chown mysql:mysql -R /var/lib/mysql2

# install mysql database
mysql_install_db --user=mysql --datadir=/var/lib/mysql2/

# run 2nd daemon
/usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql2 
--user=mysql 
--log-error=/var/log/mysqld2.log 
--pid-file=/var/lib/mysql2/mysql2.pid 
--bind-address=127.0.0.1 --port=3307 
--socket=/var/lib/mysql2/mysql2.sock &

Then connect to the 2nd instance with mysql

mysql --port 3307 --socket=/var/lib/mysql2/mysql2.sock 
Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top