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.
|
|
cp /etc/my.cnf /etc/my-3307.cnf |
Add a line like this:
to the “[mysqld]” section. Edit /etc/my-3307.cnf and change:
to
|
|
datadir=/var/lib/mysql-3307 |
Change:
|
|
socket=/var/lib/mysql/mysql.sock |
to:
|
|
socket=/var/lib/mysql-3307/mysql.sock |
Change the following lines:
|
|
log-slow-queries=/var/lib/mysqllogs/slow-log log-bin=/var/lib/mysqllogs/bin-log log-bin-index=/var/lib/mysqllogs/bin-log.index relay-log=/var/lib/mysqllogs/relay-log relay-log-index=/var/lib/mysqllogs/relay-log.index log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid |
to:
|
|
log-slow-queries=/var/lib/mysqllogs-3307/slow-log log-bin=/var/lib/mysqllogs-3307/bin-log log-bin-index=/var/lib/mysqllogs-3307/bin-log.index relay-log=/var/lib/mysqllogs-3307/relay-log relay-log-index=/var/lib/mysqllogs-3307/relay-log.index log-error=/var/log/mysqld-3307.log pid-file=/var/run/mysqld/mysqld-3307.pid |
Change server-id to a unique value:
2. Setup a new service control script.
|
|
cp /etc/init.d/mysqld /etc/init.d/mysqld-3307 |
Edit /etc/init.d/mysqld-3307 and add this line:
directly after:
|
|
# Source networking configuration. . /etc/sysconfig/network |
so that you have:
|
|
# Source networking configuration. . /etc/sysconfig/network MYCNF=/etc/my-3307.cnf |
Next change this function:
|
|
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 default result="$3" fi } |
to:
|
|
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 default result="$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:
|
|
replace 'prog="MySQL"' 'prog="MySQL-3307"' -- /etc/init.d/mysqld-3307 replace '/usr/bin/mysqld_safe' '/usr/bin/mysqld_safe --defaults-file=$MYCNF' \ -- /etc/init.d/mysqld-3307 replace 'mysqld.pid' 'mysqld-3307.pid' -- /etc/init.d/mysqld-3307 replace '/var/lock/subsys/mysqld' '/var/lock/subsys/mysqld-3307' -- /etc/init.d/mysqld-3307 |
3. Setup directories
|
|
mkdir /var/lib/mysql-3307 /var/lib/mysqllogs-3307 chown mysql.mysql /var/lib/mysql-3307/ /var/lib/mysqllogs-3307 chmod o-rwx /var/lib/mysqllogs-3307 |
4. Set service to start on boot
|
|
/sbin/chkconfig mysqld-3307 on |
5. Start the new instance:
|
|
/sbin/service mysqld-3307 start |
On