服装公司网站策划方案,试用网站 源码,宣传网站设计,西安网站建设d西安搜推宝网络公司有未知台服务器#xff0c;以后都要自己来接管。MySQL主从是必需要会的技术#xff0c;所以加强学习一下以图以后安稳日子啊#xff01; 主服务器#xff08;master#xff09;: 192.168.30.204#xff0c;用yum安装的MySQL.#xff08;内有多个库#xff09; 从服… 公司有未知台服务器以后都要自己来接管。MySQL主从是必需要会的技术所以加强学习一下以图以后安稳日子啊 主服务器master: 192.168.30.204用yum安装的MySQL.内有多个库 从服务器slave : 192.168.30.3 用yum安装的MySQL新安装 配置的主要流程是 主服务器master: 1。编辑MySQL配置文件/etc/my.cnf log-binmysql-bin #启动二进制文件 server-id1 # 1为master端ID #binlog-do-dbzabbix #指定需要同步的库 #binlog-ingore-dbmysq,test #指定不需要同步的库 数据库的设置 mysql grant replication slave on *.* to root192.168.30.3 identified by 123456; # 给IP地址为192.168.30.3上的MySQL用户root用户受予可复制权mysql flush tables with read lock; #先关闭数据库的写入防止同步时有数据出入。mysql flush privileges; mysql show master status;------------------------------------------------------------| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |------------------------------------------------------------| mysql-bin.000001 | 584530 | | |------------------------------------------------------------1 row in set (0.00 sec) mysql quit; # mysqldump --all-databases -u root -p all.sql 导出数据库 #scp ./all.sql root192.168.30.204:/root/. 复制导出的数据库到从服务器上 从服务器slave: 新安装MySQL之后设置root用户密码并导入主服务器中的数据 mysql -uroot -p all.sql 编辑配置文件/etc/my.cnf server-id 2 #设置server-id为2以上的值 mysql flush tables with read lock; 先锁定对数据库的写入 mysql change master to master_host192.168.30.204, master_userroot, master_password123mmn, master_log_filemysql-bin.000001, master_log_pos584530; 最后分别在主服务器和从服务上开启服务 主 mysql unlock tables; 从 msyql start slave start; unlock tables; 最后的检查验证 mysql show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.30.204 Master_User: root Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000002 Read_Master_Log_Pos: 3268381 Relay_Log_File: mysqld-relay-bin.000005 Relay_Log_Pos: 3268526 Relay_Master_Log_File: mysql-bin.000002 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: 3268381 Relay_Log_Space: 3268827 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.09 sec) mysql 有高亮颜色字体的语句结果表明主从服务正常开启并运行了。 在主服务器上新增一个表再到从服务器上查看是否有这个新增的表就可验证主从服务器是否正常了。 转载于:https://blog.51cto.com/fengzhige/1029755