mysql主從配置
首先可以參考我原來寫的mysql在Linux(CentOS)下主從配置詳解,在此基礎之上加一些簡單的操作就可以配置成功啦斑司。
配置過程
以下稱呼的主庫和從庫都是原始配置主從的主庫和從庫
- 將從庫像主庫一樣建立
binlog
文件夾并在/etc/my.cnf
下配置主庫信息戚宦,mysqld
下面大概是這些信息雨饺,僅供參考。
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
datadir = /data/mysql
port = 3306
character-set-server=utf8
# server_id = .....
socket = /data/mysql/mysql.sock
server-id=102
relay-log=/data/mysql_slave/relaylog/mysql-relay-bin.log
relay-log-index=/data/mysql_slave/relaylog/mysql-relay-bin.index
relay_log_purge=on
log-bin=/data/mysql_master/binlog/mysql-bin.log
log-bin-index=/data/mysql_master/binlog/mysql-bin.index
read-only=on
同樣主庫也去像從庫一樣配置這些信息收毫,這里就不贅述了署隘,接下來都重啟一下喉脖。
# service mysql restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
- 查看從庫的master運行狀態(tài)
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 120 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
- 在從庫中添加slave用戶
mysql> GRANT REPLICATION SLAVE ON *.* TO 'slave'@'your-slave-ip' IDENTIFIED BY 'your-password';
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user; +-------------------------------------+
| query |
+-------------------------------------+
| User: 'root'@'%'; |
| User: 'slave'@'your-slave-ip'; |
| User: 'root'@'127.0.0.1'; |
| User: 'root'@'::1'; |
| User: 'root'@'vm\_61\_211\_centos'; |
+-------------------------------------+
5 rows in set (0.00 sec)
- 主庫中導入
mysql> change master to master_host='119.29.105.144',master_user='slave',master_password='dsg-password',master_port=3306,MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=120;
mysql> slave start;
mysql> show slave status\G;
像原來配置主從一樣成功便是成功。
如果連接不上宾抓,別忘了將從庫的防火墻打開碌更。
# service firewalld stop