mysql主从复制(二)
1.mysql安装
yum install -y mysql mysql-devel mysql-server mydql-libs
2.修改mysql配置文件
//先备份
cp /etc/my.cnf /etc/my.cnf.bak
vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
symbolic-links=0
log-bin=mysql-bin
server-id=1
auto_increment_offset=1
auto_increment_increment=2
[mysql_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
replicate-do-db=all
3.创建目录
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
4.重启mysql
/etc/init.d/mysqld restart
5.修改slave mysql中的my.cnf
与master的文件一致,只需修改:
server-id=2
auto_increment_offset=2
[mysql_safe]
master-host=192.168.33.10
master-user=zhangsan
master-pass=123456
master-port=3306
master-connect-retry=60
修改完成后,同样需要执行3、4步骤
6.master上执行授权
grant replication slave on *.* to 'zhangsan'@'%' identified by '123456';
show master status
7.slave上指定主服务器
mysql> change master to master_host='192.168.33.10',master_user='zhangsan',master_password='123456',master_log_file='mysql-bin.0000006',master_log_pos=98;
说明:master_log_file,master_log_pos 这两个参数的值,可以通过show master status查看。
mysql> slave start
mysql> show slave status\G
说明:如果以下两个值为yes,表明连接正常,等待同步。
slave_IO_Running:Yes
Slave_SQL_Running:Yes
【励志篇】:
古之成大事掌大学问者,不惟有超世之才,亦必有坚韧不拔之志。