在测试Mysql多主一从服务器,即一个从服务器多端口同步不同主库。本文记录了开启不同端口的操作。

详细步骤:

1首先要先把my.cnf配置文件复制一份,开几个端口要复制几份当然要重新命名.

如:

  1. cp /usr/local/mysql/my.cnf /usr/local/mysql/my3307.cnf

  2. cp /usr/local/mysql/my.cnf /usr/local/mysql/my3308.cnf

  3. cp /usr/local/mysql/my.cnf /usr/local/mysql/my3309.cnf

2修改my3306.cnf my3307.cnf my3308.cnf文件把默认的3306端口改成 3307 3308 3309.

如:

[client]

port = 3308

socket = /tmp/mysql3308.sock

default-character-set=UTF

[mysqld]

port = 3308

socket = /tmp/mysql3308.sock

basedir = /usr/local/mysql

datadir = /www/mysqldata8

3、初始化数据库

/usr/local/mysql/scripts/mysql_install_db  --datadir=/usr/local/mysql/mysqldata3306/ --user=mysql --basedir=/usr/local/mysql

/usr/local/mysql/scripts/mysql_install_db  --datadir=/usr/local/mysql/mysqldata3307/ --user=mysql --basedir=/usr/local/mysql

/usr/local/mysql/scripts/mysql_install_db  --datadir=/usr/local/mysql/mysqldata3308/ --user=mysql --basedir=/usr/local/mysql

4、启动mysql,要指定.cnf文件和目录启动

/usr/local/mysql/bin/mysqld_safe  --defaults-extra-file=/usr/local/mysql/my3307.cnf  --datadir=/usr/local/mysql/data/mysqldata3307 --user=mysql  &

/usr/local/mysql/bin/mysqld_safe  --defaults-extra-file=/usr/local/mysql/my3308.cnf   --datadir=/usr/local/mysql/data/mysqldata3308 --user=mysql  &

/usr/local/mysql/bin/mysqld_safe  --defaults-extra-file=/usr/local/mysql/my3309.cnf   --datadir=/usr/local/mysql/data/mysqldata3309 --user=mysql  &

5停止MYSQL,对应的sock文件。

/usr/local/mysql/bin/mysqladmin  -uroot -S /tmp/mysql3308.sock shutdown

6登陆mysql

mysql -S /tmp/mysq3308.sock  -P  3308


ps:

关于mysql.sock文件是使用相同的文件还是使用原文件进行链接,我也不确定。我的方法是将mysql.sock文件进行链接了。

ln -sf /tmp/mysql.sock /tmp/mysql3307.sock