时间:2021-07-01 10:21:17 帮助过:23人阅读
mysql> show master status; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000003 | 476 | | | +------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)
4:在从服务器上修改自己的master的数据库
登入数据库
[root@slave ~]# mysqladmin -uroot password 123123 [root@slave ~]# mysql -uroot -p123123
设置从服务器读取master bin-log的相关信息
mysql> change master to -> master_host=‘192.168.100.150‘, ##master的ip -> master_user=‘slave‘, ##授权允许复制的用户名 -> master_password=‘123123‘, ##授权允许复制密码 -> master_log_file=‘mysql-bin.000003‘, ##bin-log文件名,上一步在master上查到的信息 -> master_log_pos=476; ##偏移量,在master上查到的信息 Query OK, 0 rows affected (0.07 sec)
启动slave
mysql> start slave; Query OK, 0 rows affected (0.00 sec)
插卡slave状态:
##查到的状态这两个为yes,下面没有error错误就正常 Slave_IO_Running: Yes Slave_SQL_Running: Yes
mysql> show slave status\G; *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.100.150 Master_User: slave Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000003 Read_Master_Log_Pos: 706 Relay_Log_File: mysqld-relay-bin.000002 Relay_Log_Pos: 481 Relay_Master_Log_File: mysql-bin.000003 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 706 Relay_Log_Space: 637 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: 1 row in set (0.00 sec) ERROR: No query specified mysql>
5:测试:
在主数据库上新建库,查看库
mysql> mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | +--------------------+ 3 rows in set (0.00 sec) mysql> create database test_databases; Query OK, 1 row affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | | test_databases | +--------------------+ 4 rows in set (0.00 sec)
在从数据库上查看库:
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | | test_databases | +--------------------+ 4 rows in set (0.00 sec)
(可以看到在主数据库上新建的库,复制过来了)
删除操作也是可以同步的:
主:
mysql> drop database test_databases; Query OK, 0 rows affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | +--------------------+ 3 rows in set (0.00 sec) mysql>
从:
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | +--------------------+ 3 rows in set (0.00 sec) mysql>
本文出自 “向往技术的小白” 博客,请务必保留此出处http://lesliecheung.blog.51cto.com/12622169/1958255
mysql主从复制
标签:mysql主从复制