- 主从服务器安装相同服务....略
- 配置主服务器
vim /etc/my.conf
[mysqld]
log-bin=mysql-bin
server-id=1
- 启动主服务, 并配置同步账号
systemctl start mysqld
//登录mysql
GRANT REPLICATION SLAVE ON *.* TO 'userName'@'%' IDENTIFIED BY 'yourPassword';
FLUSH PRIVILEGES;
show master status; //记住File 和Position
mysqldump dbname -uroot -p > dbname.sql //将对应库导出来.
- 修改从服务配置
vim /etc/my.conf
[mysqld]
server-id=2
- 启动从服务, 并配置同步配置
systemctl start mysqld //启动服务
mysql -uroot -p //登录
source /path/to/dbname.sql //导入数据
CHANGE MASTER TO MASTER_HOST='masterServerIp', MASTER_PORT=masterPort, MASTER_USER='masterUser', MASTER_PASSWORD='masterPassword', MASTER_LOG_FILE='masterLogFile', MASTER_LOG_POS=masterPosition;
start slave;