MySql 安装:(centos)
[root@master_1 ~]#yum -y install mysql-server mysql-devel mysql mysql-bench mysql-test
启动 MySql:
[root@master_1 ~]#/etc/init.d/mysqld start
配置文件位置:
/etc/my.cnf
安装目录:
/var/lib/mysql
MySql 主从配置:
mysql master:192.168.1.6 slave:192.168.1.8
1 修改master 配置
vim /etc/my.cnf
2.修改slave配置
vim /etc/my.cnf
3. 在master机器上生成用户
4. 查看master 状态
5. 执行表复制
master:
FLUSH TABLES WITH READ LOCK;
reset master;
cd /var/lib/
tar zcvf mysql.tar.gz mysql
scp mysql.tar.gz root@192.168.1.8:/var/lib/
UNLOCK TABLES;
6 设置slave主机
在slave上执行:
mysql> slave stop; Query OK, 0 rows affected (0.00 sec) mysql> change master to -> master_host='192.168.1.6', -> master_user='backup1', -> master_password='123456', -> master_log_file='mysql-bin.000001', -> master_log_pos=106; Query OK, 0 rows affected (0.04 sec) mysql> slave start; Query OK, 0 rows affected (0.00 sec) mysql> show slave status\G; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.1.6 Master_User: backup1 Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000001 Read_Master_Log_Pos: 106 Relay_Log_File: mysqld-relay-bin.000002 Relay_Log_Pos: 251 Relay_Master_Log_File: mysql-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: test Replicate_Ignore_DB: mysql 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: 106 Relay_Log_Space: 407 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)
7 测试:
master:
slave: