Mysql 主从同步



Mysql master slave syn (for window7)
1. the mysql version is the same,
2. download mysql, for version 5.6
3. if free installation version, you need configure my.ini as follow, notice the server_id must be

different from each other
server_id=1
basedir = D:\MySQL\mysql
datadir = D:\MySQL\mysql\data
port = 3307
log-bin=mysql-bin
replicate-wild-do-table = tvugs.%
replicate_wild_ignore_table = mysql.%

4. run cmd as administrator. Enter the mysql to find mysqld, run the command
mysqld --install mysql_service_name --defaults-file="D:\MySQL\mysql\my.ini
note, mysql_service_name, you can name it arbitrary.

5. launch the mysql,
net start mysql_service_name(the name is before you named)

6.  create an account and authorize the slave at master, you'd beeter not use root
GRANT REPLICATION SLAVE ON *.* to 'slaveuser'@'%' identified by '123456'

7. login the master and show the master status
mysql>show master status;
+------------------+----------+--------------+------------------+
   | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
   +------------------+----------+--------------+------------------+
   | mysql-bin.000004 |      308 |              |                  |
   +------------------+----------+--------------+------------------+
note, don't operate the master in case the value of the master status is changed.

8. configure the slave
mysql>change master to

master_host='192.168.145.222',master_port=3307,master_user='slaveuser',master_passwo

rd='123456', master_log_file='mysql-bin.000004',master_log_pos=308;  

if master_port is 3306, you can ignore it, or you need it and not single qote, as the

master_log_pos

mysql>start slave;

9. view the slave copy status
mysql>show slave status
if Slave_IO_Running and Slave_SQL_Running are both yes, it is just ok.


for linux or centos it is the same as windows 7, but has a little difference.

1. use find command to find the file my.cnf (/usr/my.cnf  /etc/my.cnf)

2. service mysql restart.



你可能感兴趣的:(Mysql 主从同步)