MySQL主从配置
配置准备将要配置的数据库进行主从同步,主从的服务器上都要有同一个数据库
一、配置mysql主服务器
[root@master ~] # vim /etc/my.cnf .................................... log-bin=mysql-bin <== 打开日志格式 .................................... server- id =1 <== 主从标记 ............................... [root@master backup] # mysql -uroot -p Enter password: mysql> grant replication slave on *.* to ‘repl‘ @ ‘192.168.1.13‘ identified by ‘123‘ ; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) mysql> flush tables with read lock; Query OK, 0 rows affected (0.00 sec) mysql> show master status; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000014 | 332 | | |
二、配置mysql从服务器 |
# 修改从mysql的配置文件 [root@slave ~] # vim /etc/my.cnf ............................... server- id =2 修改 id 号,用来区分主从服务器标识 ............................... [root@slave tmp] # mysql -uroot -p Enter password: mysql> slave stop; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> change master to master_host= ‘192.168.1.11‘ , master_port=3306, master_user= ‘repl‘ , master_password= ‘123‘ , master_log_file= ‘mysql-bin.000014‘ , master_log_pos=332; Query OK, 0 rows affected (0.08 sec) mysql> slave start; Query OK, 0 rows affected (0.01 sec) mysql> show slave status\G; *************************** 1. row *************************** ERROR: No query specified |
接下来就可以测试主从服务器了
本文出自 “linux运维” 博客,请务必保留此出处http://linuxshare.blog.51cto.com/8944591/1671446
原文地址:http://linuxshare.blog.51cto.com/8944591/1671446