标签:初始化 就会 ble 导入 rip tmp awk dump pass
安装、配置MySQL配置主从准备工作
设定mysql_2 为主端口3307,mysql为从端口为3306
在主上创建测试库: create database db1;
然后导出主的mysql库数据然后导入给db1
mysqldump -uroot -S /tmp/mysql2.sock mysql > 123.sql ;
mysql -uroot -S /tmp/mysql2.sock db1 < 123.sql
配置主(master)
vim /usr/local/mysql_2/my.cnf #修改或添加:
server-id=1
log-bin=mysql-bin
两个可选参数(2选1):
binlog-do-db=db1,db2 #需要同步的库
binlog-ignore-db=db1,db2 #忽略不同步的库
修改配置文件后,重启mysql_2
pid=ps uax |grep mysql2.sock |grep -v grep |awk ‘{print $2}‘
; kill $pid; cd /usr/local/mysql_2/bin/; ./mysqld_safe --defaults-file=../my.cnf --user=mysql &
设置root密码:mysqladmin -u root -S /tmp/mysql2.sock password ‘123456‘
mysql -u root -S /tmp/mysql2.sock -p‘123456‘
grant replication slave on . to ‘repl‘@‘127.0.0.1‘ identified by ‘123123‘;
flush tables with read lock;
show master status; #一定要记住前两列的内容,一会会用到
设置从(slave)
vim /etc/my.cnf #修改或增加
server-id = 2 #这个数值不能和主一样
可选参数:replicate-do-db=db1,db2 和 replicate-ignore-db=db1,db2 #意义同主的那两个可选参数
service mysqld restart
拷贝主的db1库数据到从:mysqldump -uroot -S /tmp/mysql2.sock -p123456 db1 > db1.sql; mysql -uroot -p -e "create database db1"; mysql -uroot -p db1 < db1.sql
mysql -uroot -p #登陆从的mysql
slave stop;
change master to master_host=‘127.0.0.1‘, master_port=3307, master_user=‘repl‘, master_password=‘123123‘, master_log_file=‘mysql-bin.000006‘, master_log_pos=474952;
slave start;
主上: mysql -uroot -S /tmp/mysql2.sock -p123456 -e "unlock tables"
从上查看从的状态: show slave status\G;
标签:初始化 就会 ble 导入 rip tmp awk dump pass
原文地址:http://blog.51cto.com/amazing61/2063916