1、安装同一mysql版本。
2、修改master配置文件:/etc/my.cnf
expire-logs-days = 3
skip-external-locking
skip-name-resolve
port = 3306
log-bin=mysql-bin
server-id =1
重启master。
3、修改slave配置文件:/etc/my.cnf
expire-logs-days = 3
skip-external-locking
skip-name-resolve
log-bin=mysql-bin
server-id =2
重启slave
4、master新建授权。
GRANT REPLICATION SLAVE ON *.* to ‘slave01’@’10.172.218.3’ identified by ‘8cb0682cb4′;
5、slave用slave01账号远程登陆测试:mysql -u slave01 -p8cb0682cb4 -h10.170.194.171
6、slave服务器建同名库。
7、master锁库: flush tables with read lock; //不要退出这个终端,否则这个锁就不生效了。
同时要记录下mysql-bin.000009和pos号。
show master status;
8、master导出数据: mysqldump -u root -p8cb0682cb4 amgdmp > amgdmp.sql
9、slave 导入数据:进入mysql执行source /tmp/amgdmp.sql;或者:mysql -u用户名 -p密码 数据库名 < 数据库名.sql
10、slave上指定同步指令:change master to master_host=’10.170.194.171′,master_user=’slave01′,master_password=’8cb0682cb4′,master_log_file=’mysql-bin.000009′,master_log_pos=252;
start slave;
11、master解锁:unlock tables;
12、:show slave status\G;
Slave_IO_Running: Yes //此状态必须YES
Slave_SQL_Running: Yes //此状态必须YES
其他:
1、mysql建立用户:grant all privileges on jira.* to jira@’192.168.1.10’ identified by ‘abcd-1234′;
2、删除用户:Delete FROM user Where User=’test’ and Host=’localhost’;flush privileges;
3、修改密码:update mysql.user set password=password(‘新密码’) where User=”test” and Host=”localhost”;flush privileges;