Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure MySQL on same machine with different port?

Tags:

mysql

port

my.cnf

How to configure two different port for MySQL on same machine? I know that default port is 3306. But I also want to configure 3307 and 3308. Is it possible?

One bonus question with current one ;)

Can we assign Different Ports to Different Databases and also can assign/create Credentials respectively?

like image 709
NullPointer Avatar asked Sep 30 '13 13:09

NullPointer


People also ask

Can MySQL listen 2 ports?

Unfortuantely the MySQL port can serve only ONE client.

How can I change MySQL port from 0 to 3306?

You need to edit your mysql config file, my. cnf in /etc/my. cnf and change the port to 3306. Then restart mysql.


2 Answers

You can use the --port=port_num option. Have a look here for more information on how to configure multiple mysql instances.

like image 60
Ivaylo Strandjev Avatar answered Oct 23 '22 09:10

Ivaylo Strandjev


You can copy /etc/mysql/my.cnf, change the port in it and change the pathes to data dirs as well, because i'm pretty sure You can't have more than 1 instance of mysql serving from the same directories.

Check http://dev.mysql.com/doc/refman/5.1/en/multiple-servers.html.

ex :

cp /etc/mysql/my.cnf /etc/mysql/my-3307.cnf
//edit my-3307.cnf, for example
port = 3307
basedir = /var/lib/mysql-3307
datadir = /var/lib/mysql-3307
//end-edit
mysql_upgrade --defaults-file=/etc/mysql/my-3307.cnf #checks the syntax and creates the dirs you need.
#start mysqld
mysqld --defaults-file=/etc/mysql/my-3307.cnf
like image 26
OneOfOne Avatar answered Oct 23 '22 10:10

OneOfOne