To setup an alternate instance of MySQL listening on TCP port 3307 on a RHEL5 server follow these steps.
1. Setup a new MySQL config file.
12 cp /etc/my.cnf /etc/my-3307.cnf
Add a line like this:
1 port = 3307
to the “[mysqld]” section.
Edit /etc/my-3307.cnf and change:
12 datadir=/var/lib/mysql
to
12 datadir=/var/lib/mysql-3307
Change:
123 socket=/var/lib/mysql/mysql.sock
to:
123 socket=/var/lib/mysql-3307/mysql.sock
Change the following lines:
123456789 log-slow-queries=/var/lib/mysqllogs/slow-loglog-bin=/var/lib/mysqllogs/bin-loglog-bin-index=/var/lib/mysqllogs/bin-log.indexrelay-log=/var/lib/mysqllogs/relay-logrelay-log-index=/var/lib/mysqllogs/relay-log.indexlog-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid
to:
123456789 log-slow-queries=/var/lib/mysqllogs-3307/slow-loglog-bin=/var/lib/mysqllogs-3307/bin-loglog-bin-index=/var/lib/mysqllogs-3307/bin-log.indexrelay-log=/var/lib/mysqllogs-3307/relay-logrelay-log-index=/var/lib/mysqllogs-3307/relay-log.indexlog-error=/var/log/mysqld-3307.logpid-file=/var/run/mysqld/mysqld-3307.pid
Change server-id to a unique value:
123 server-id=2
2. Setup a new service control script.
123 cp /etc/init.d/mysqld /etc/init.d/mysqld-3307
Edit /etc/init.d/mysqld-3307 and add this line:
123 MYCNF=/etc/my-3307.cnf
directly after:
1234 # Source networking configuration.. /etc/sysconfig/network
so that you have:
123456 # Source networking configuration.. /etc/sysconfig/networkMYCNF=/etc/my-3307.cnf
Next change this function:
123456789 get_mysql_option(){result=`/usr/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1`if [ -z "$result" ]; then# not found, use defaultresult="$3"fi}
to:
123456789 get_mysql_option(){result=`/usr/bin/my_print_defaults -c $MYCNF "$1" | sed -n "s/^--$2=//p" | tail -n 1`if [ -z "$result" ]; then# not found, use defaultresult="$3"fi}
Notice that the change is to add “-c $MYCNF” to the call to “my_print_defaults”.
Finally run the following search/replace commands to fixup the program name, add defaults file to mysqld_safe call and set unique pid and subsys files:
1234567 replace 'prog="MySQL"' 'prog="MySQL-3307"' -- /etc/init.d/mysqld-3307replace '/usr/bin/mysqld_safe' '/usr/bin/mysqld_safe --defaults-file=$MYCNF' \-- /etc/init.d/mysqld-3307replace 'mysqld.pid' 'mysqld-3307.pid' -- /etc/init.d/mysqld-3307replace '/var/lock/subsys/mysqld' '/var/lock/subsys/mysqld-3307' -- /etc/init.d/mysqld-3307
3. Setup directories
1234 mkdir /var/lib/mysql-3307 /var/lib/mysqllogs-3307chown mysql.mysql /var/lib/mysql-3307/ /var/lib/mysqllogs-3307chmod o-rwx /var/lib/mysqllogs-3307
4. Set service to start on boot
123 /sbin/chkconfig mysqld-3307 on
5. Start the new instance:
123 /sbin/service mysqld-3307 start
On the first startup you should see some output like this:
123456789101112131415161718192021222324252627282930313233343536373839 Initializing MySQL database: Installing MySQL system tables...OKFilling help tables...OKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !To do so, start the server, then issue the following commands:/usr/bin/mysqladmin -u root password 'new-password'/usr/bin/mysqladmin -u root -h 244418-web3.www.idtweet.com password 'new-password'Alternatively you can run:/usr/bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default. This isstrongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with:cd /usr ; /usr/bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.plcd mysql-test ; perl mysql-test-run.plPlease report any problems with the /usr/bin/mysqlbug script!The latest information about MySQL is available on the web athttp://www.mysql.comSupport MySQL by buying support/licenses at http://shop.mysql.com[ OK ]Starting MySQL-3307: [ OK ]
6. Set MySQL root password.
1 /usr/bin/mysqladmin -P 3307 -h 127.0.0.1 -u root --password="" password password 'new-password'
And that’s it. You now have an new instance of MySQL listening on port 3307.
Remember that you must tell the mysql command line utilities where to find the instance. For example:
12 mysql -P 3307 -h 127.0.0.1
or
1 mysql -S /var/lib/mysql-3307/mysql.sock
Also keep in mind that by default any .my.cnf file in your home directory will be used. You may have to override settings in the .my.cnf file and explicitly provide the user and password when connecting.




