MYSQL version: 4.1
Environment introduction: main database 192.168.0.205 slave database 192.168.0.206
1. Create /etc/my.cnf in the main database, modify the key value in [mysqld] and add
server-id=1
log-bin=binlog_name
2. Add a user to the main library to read main library logs from the slave library.
grant replication slave,reload,super on *.* to 'slave'@'192.168.0.206' identified by '123456'
3. Connect the slave library to the main library for testing.
/opt/mysql/bin/mysql -u slave -p -h 192.168.0.205
4. Stop the slave library, modify the slave library /etc/my.cnf, and add options:
[mysqld] |
5. Start the slave database and synchronize the master-slave database data
/opt/mysql/share/mysql/mysql start
/opt/mysql/bin/mysql -u root -p
mysql>load data from master;
Note: This step can also be used Pour into the database or take the test directly from the directory.
6. Test:
create a table in the main database,
mysql>create database sampdb; |
Open the slave library and view:
/opt/mysql/bin/mysql -u root -p |
It means that the master-slave database is created successfully.
7. Master-slave database related commands:
slave stop; slave start; start to stop the slave database.
show slave statusG; Show which master database binary log is being read from the slave database
purge master logs to 'binlog.000004'; This command is very careful to delete the useless binary log files of the master database. If deleted by mistake, there will be no way to automatically update the slave library.
change master; modify parameters from the server.