如上面所说:http://www.cnblogs.com/super-d2/p/3851957.html
安装好mysql;
mysql_multi方式配置Mysql数据库主从
授予用于同步用的用户同步数据的权限
grant replication slave on *.* to ‘slave3306‘@‘127.0.0.1‘ identified by ‘3306‘;
flush privileges;
此时查看主从状态,如下
show master status;
配置多数据库:
内容如下:
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
#user = mysql
#password = my_password
[mysqld1]
socket = /usr/local/var/mysql1/mysql1.sock
port = 3306
pid-file = /usr/local/var/mysql1/mysql1.pid
datadir = /usr/local/var/mysql1
#language = /usr/local/mysql/share/mysql/english
user = mysql
server-id = 1
[mysqld2]
socket = /usr/local/var/mysql2/mysql2.sock
port = 3307
pid-file = /usr/local/var/mysql2/mysql2.pid
datadir = /usr/local/var/mysql2
#language = /usr/local/mysql/share/mysql/english
user = mysql
server-id = 2
[mysqld3]
socket = /usr/local/var/mysql3/mysql3.sock
port = 3308
pid-file = /usr/local/var/mysql3/mysql3.pid
datadir = /usr/local/var/mysql3
#language = /usr/local/mysql/share/mysql/english
user = mysql
server-id = 3
[mysqld4]
socket = /usr/local/var/mysql4/mysql4.sock
port = 3309
pid-file = /usr/local/var/mysql4/mysql4.pid
datadir = /usr/local/var/mysql4
#language = /usr/local/mysql/share/mysql/english
user = mysql
server-id = 4
(2)启动数据库实例
mysqld_multi --defaults-extra-file=/etc/ mysqld_multi.cnf start #启动
mysqld_multi --defaults-extra-file=/etc/mysqld_multi.cnf stop #关闭
mysqld_multi --defaults-extra-file=/etc/mysqld_multi.cnf report #查看状态
(3)主从配置:
进入主库
[root@infa mysql]# mysql -uroot -p -h127.0.0.1 -P3306
mysql> reset master;
然后到从库:
slave stop;
reset slave;
slave start;
到主库看看:
从库连接已经存在了;
(4)、验证是否真正的同步了:
登录主库3306:
OK,证明数据同步成功了!
如果主键id重复可以尝试下:
set global server_id = 13;
(
疑问:现在那个server_id我是动态设置的,就像下面这样子
set global server_id = 13; 会不会重启mysql之后这些信息全部都没有了?
答复:以现在这状态验证,不会有影响
)
最后,备注几个常用的命令:
show processlist
set global server_id = 13;
slave stop;
reset slave;
slave start;
reset master;
show grants for slave3306@‘127.0.0.1‘;
mysql_multi方式配置Mysql数据库主从,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/super-d2/p/3852192.html