Reputation: 2758
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?
Upvotes: 10
Views: 44055
Reputation: 858
I'm using CentOS. Not is too simple,
Upvotes: 0
Reputation: 21911
mysqld_multi is by far the best way to handle different instances of mysql.
Some more useful tips:
mysqld_multi --example
/var/lib/mysql2
if you get weird permission errors.Upvotes: 1
Reputation: 99224
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
Upvotes: 5
Reputation: 3205
You can launch several instance of mysql :
mysqld_safe --defaults-file=/path/to/my.cnf1
mysqld_safe --defaults-file=/path/to/my.cnf2
mysqld_safe --defaults-file=/path/to/my.cnf3
and change the port parameter in the [mysqld] section of each my.cnf.
If you want to have only one mysqld process/database you can use port redirection (with linux) :
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 3307 -j REDIRECT --to-port 3306
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 3308 -j REDIRECT --to-port 3306
Upvotes: 7
Reputation: 70929
You can use the --port=port_num
option. Have a look here for more information on how to configure multiple mysql instances.
Upvotes: 10