码迷,mamicode.com
首页 > 数据库 > 详细

mysql_multi方式配置Mysql数据库主从

时间:2014-07-18 16:02:00      阅读:328      评论:0      收藏:0      [点我收藏+]

标签:blog   http   os   数据   2014   art   

如上面所说: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;

配置多数据库:

bubuko.com,布布扣

内容如下:

[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

bubuko.com,布布扣

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

bubuko.com,布布扣

mysql> reset master;

然后到从库: 

slave stop;

reset slave;

slave start; 

bubuko.com,布布扣

到主库看看:

bubuko.com,布布扣

从库连接已经存在了;

 

(4)、验证是否真正的同步了:

登录主库3306:

bubuko.com,布布扣

bubuko.com,布布扣

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‘;

show privileges; 
 
select user,host from mysql.user;
 
change master to master_host=‘127.0.0.1‘,master_port=3306,master_user=‘slave3306‘,master_password=‘3306‘,master_log_file=‘mysql-bin.000004‘,master_log_pos=1641; 
 
show master status 
show slave status\G;
 
总结了一下:
实际上是先在主库里面赋予一个用户从机权限,然后再到从库里面按把从库的master指向主库,那个从机用户实际上是拿来做同步数据用的,然后做的过程中主库的server_id与从库的server_id不能相同 ;
 
 
 
 

mysql_multi方式配置Mysql数据库主从,布布扣,bubuko.com

mysql_multi方式配置Mysql数据库主从

标签:blog   http   os   数据   2014   art   

原文地址:http://www.cnblogs.com/super-d2/p/3852192.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!