主ip:192.168.1.1
从ip:192.168.1.2
主:#vim /etc/my.cnf
添加:binlog-do-db=charlesdb ##自己创建的同步数据库,这里是charlesdb
binlog-ignore-db=mysql
修改:server_id=1 ##server_id要不同
#service mysqld restart ##重启MySQL服务使配置文件生效
#mysql -u root -p密码
>create database charlesdb;
>use mysql
>insert into mysql.user(Host,User,Password) values(‘localhost‘,‘charles‘,password(‘redhat‘));
>grant replication slave on *.* to ‘charles‘@‘192.168.1.2‘ identified by ‘redhat‘;
>flush privileges;
>show master status;
>exit
#mysqldump -u root -p charlesdb > ~/root/charlesdb.sql
:输入本机密码
#scp charlesdb.sql [email protected]:/root
:yes
:1.2密码
从:#vim /etc/my.cnf
添加:binlog-do-db=charlesdb
binlog-ignore-db=mysql
修改:server_id=2
#service mysqld restart
#mysql -u root -p密码
>create database charlesdb;
>use charlesdb;
>source charleddb.sql;
>slave stop;
>change master to
master_host=‘192.168.1.1‘,
master_user=‘charles‘,
master_password=‘redhat‘,
master_log_file=‘1.1上的偏移量‘,
master_log_pos=1.1上的端口号;
>slave start;
>show slave status\G;