mysqldump -uroot -psphinx lb8844 oho_ask_question>/usr/local/ask.sql 退出数据库,导入sql文件 mysql -uroot -p123456 lb8844 < lb8844_2009.sql 数据库复制 主机/etc/my.cnf设置 server-id = 10(不设置为1,因为1通常是服务器的默认值,容易混淆) 打开二进制日志 log-bin=mysql-bin binlog_format=mixed 重启mysql service mysql restart 从机/etc/my.cnf设置 server-id = 2 master-host=192.168.10.201 master-user=sync master-password=8844sync master-connect-retry=10 replicate-do-db=lb8844 binlog-ignore-db=mysql 重启mysql service mysql restart 在主机中查看是否打开二进制日志 进入mysql show master status; mysql> show master status; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000001 | 889 | | | +------------------+----------+--------------+------------------+ 1 row in set (0.00 sec) ##重新设置二进制日志 reset master; mysql> reset master; Query OK, 0 rows affected (0.01 sec) 在从机中 进入mysql start slave; show slave status\G; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.10.201 Master_User: sync Master_Port: 3306 Connect_Retry: 10 Master_Log_File: mysql-bin.000001 Read_Master_Log_Pos: 889 Relay_Log_File: localhost-relay-bin.000003 Relay_Log_Pos: 1034 Relay_Master_Log_File: mysql-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: lb8844 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: 889 Relay_Log_Space: 1193 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) ERROR: No query specified 如果 Slave_IO_Running: Yes Slave_SQL_Running: Yes 这两项为yes则正确; stop slave; reset slave; start slave; 以上三项为重启slave;