在CentOS上设置MySQL主从复制时,需要正确配置主服务器和从服务器的权限。以下是设置MySQL主从权限的步骤:
安装MySQL: 确保主服务器和从服务器上都安装了MySQL。如果没有安装,可以使用以下命令进行安装:
sudo yum install mysql-server
配置主服务器:
sudo systemctl start mysqld
sudo mysql_secure_installation
CREATE USER 'repl'@'%' IDENTIFIED BY 'password';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';
FLUSH PRIVILEGES;
配置从服务器:
sudo systemctl stop mysqld
scp /var/log/mysqld.log username@master_ip:/path/to/destination
sudo systemctl start mysqld
/etc/my.cnf
文件,添加以下内容:[mysqld]
server-id=1
relay-log=relay-bin
log_bin=/var/log/mysql/mysql-bin.log
read_only=ON
CREATE USER 'repl'@'master_ip' IDENTIFIED BY 'password';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'master_ip';
FLUSH PRIVILEGES;
启动从服务器复制进程:
sudo systemctl stop mysqld
sudo mysqld --skip-slave-start --relay-log=/var/log/mysql/mysql-relay-bin.log --log-bin=/var/log/mysql/mysql-bin.log --server-id=2
CHANGE MASTER TO
MASTER_HOST='master_ip',
MASTER_USER='repl',
MASTER_PASSWORD='password',
MASTER_LOG_FILE='mysql-bin.000001',
MASTER_LOG_POS=107;
START SLAVE;
通过以上步骤,您可以在CentOS上成功设置MySQL主从复制,并正确配置相关权限。