主192.168.20.63 duwers63.space
从192.168.20.60 duwers60.space
关闭iptables selinux
主从数据库版本一致
拓扑
[root@duwers63 ~]# mysql -uroot -p123456
mysql> show variables like ‘%version%‘; #查看版本
+-------------------------+---------------------+
| Variable_name | Value |
+-------------------------+---------------------+
| protocol_version | 10 |
| version | 5.1.73-log |
| version_comment | Source distribution |
| version_compile_machine | x86_64 |
| version_compile_os | redhat-linux-gnu |
+-------------------------+---------------------+
5 rows in set (0.01 sec)
mysql> create database duwers63;
mysql> use duwers63
mysql> create table test1(id int);
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| duwers63 |
| mysql |
| ucenter |
+--------------------+
4 rows in set (0.00 sec)
[root@duwers63 ~]# service mysqld stop
[root@duwers63 ~]# vim /etc/my.cnf
添加
log-bin=mysqllog #开启二进制日志
server-id=63 #本机数据库标识
binlog-do-db=duwers63 #二进制要同步的db
[root@duwers63 ~]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommendedto prevent assorted security risks
symbolic-links=0
log-bin=mysqllog
server-id=63
binlog-do-db=tree
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@duwers63 ~]#
[root@duwers63 ~]# service mysqld start
[root@duwers63 ~]# mysql -uroot -p123456
mysql> grant replication slave on *.* toslave@192.168.20.60 identified by "123456";
mysql> show master status;
+-----------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB |Binlog_Ignore_DB |
+-----------------+----------+--------------+------------------+
| mysqllog.000001 | 257 | tree | |
+-----------------+----------+--------------+------------------+
1 row in set (0.00 sec)
[root@duwers63 ~]# ls /var/lib/mysql/
duwers63 ibdata1 ib_logfile0 ib_logfile1 mysql mysqllog.000001 mysqllog.index mysql.sock ucenter
[root@duwers63 ~]#
[root@duwers63 ~]# mysqldump -u root-p123456 -A >all.sql
[root@duwers63 ~]# scp -P 44968 all.sqlxiaowenwen@192.168.20.60:/root
[root@duwers60 ~]# service mysqld start
[root@duwers60 ~]# mysql -u slave -h192.168.20.63 -p123456 -A
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.00 sec)
[root@duwers60 ~]# mysql -u root -p</root/all.sql
[root@duwers60 ~]# vim /etc/my.cnf
添加
server-id=60
master-host=192.168.20.63
master-user=slave
master-password=123456
[root@duwers60 ~]# service mysqld restart
[root@duwers60 ~]# mysql -u root -p123456
mysql> show slave status \G
*************************** 1. row***************************
Slave_IO_State: Waiting formaster to send event
Master_Host: 192.168.20.63
Master_User: slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysqllog.000001
Read_Master_Log_Pos: 257
Relay_Log_File:mysqld-relay-bin.000002
Relay_Log_Pos: 401
Relay_Master_Log_File: mysqllog.000001
Slave_IO_Running: Yes #负责与主机的IO通信Yes说明从服务器安装成功
Slave_SQL_Running: Yes #负责自己slave mysql进程 Yes说明从服务器安装成功
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 257
Relay_Log_Space: 557
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
1 row in set (0.00 sec)
mysql> use duwers63
mysql> show tables;
+--------------------+
| Tables_in_duwers63 |
+--------------------+
| test1 |
+--------------------+
1 row in set (0.00 sec)
mysql> insert into test1 values(1);
mysql> use duwers63
mysql> select * from test1;
+------+
| id |
+------+
| 1 |
+------+
1 row in set (0.00 sec)
本文出自 “duwers” 博客,请务必保留此出处http://duwers.blog.51cto.com/7376225/1842374
原文地址:http://duwers.blog.51cto.com/7376225/1842374