mysql master reset
时间: 2023-11-06 20:46:37 浏览: 108
Reset Master Password
As an AI language model, I don't have the ability to physically reset a MySQL master server, but I can provide the general steps that can be followed to reset a MySQL master server:
1. Stop the MySQL service on the master server using the command "systemctl stop mysql" (for systems using systemd) or "service mysql stop" (for systems using init.d).
2. Edit the MySQL configuration file (usually located at /etc/mysql/my.cnf) and add the following lines under the [mysqld] section:
skip-slave-start
log-bin = /var/log/mysql/mysql-bin.log
server-id = 1
These lines will disable the replication (skip-slave-start), enable binary logging (log-bin), and set the server ID to 1.
3. Delete the binary log files and the relay log files from the data directory (usually located at /var/lib/mysql). You can do this by running the command "rm -rf /var/lib/mysql/*-bin.*".
4. Start the MySQL service using the command "systemctl start mysql" or "service mysql start".
5. Connect to the MySQL server using the command "mysql -u root -p" and run the following commands:
RESET MASTER;
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;
These commands will reset the binary log, flush the tables, and show the current master status.
6. Take note of the file name and position from the output of the SHOW MASTER STATUS command.
7. Exit the MySQL shell by running the command "exit".
8. Update the slave servers with the new master information by running the following command on each slave server:
CHANGE MASTER TO MASTER_HOST='master_hostname', MASTER_USER='replication_user', MASTER_PASSWORD='replication_password', MASTER_LOG_FILE='master_log_file_name', MASTER_LOG_POS=master_log_file_position;
Replace the values inside the single quotes with the appropriate values for your setup.
9. Start the replication on each slave server using the command "START SLAVE;".
That's it! Your MySQL master server should now be reset and ready for replication.
阅读全文