网站管理工作一般包括,男女做暖暖的视频试看网站,html教程书,室内设计培训网课一、安装环境操作系统#xff1a;CentOS-7-x86_64-DVD-1611.iso数据库版本#xff1a;mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz数据库地址#xff1a;192.168.2.1(主)192.168.2.2(从)MySQL在5.6之前和之后的安装方式是不一样的。首先保证3306端口的可用#xff0c;或者…一、安装环境操作系统CentOS-7-x86_64-DVD-1611.iso数据库版本mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz数据库地址192.168.2.1(主)192.168.2.2(从)MySQL在5.6之前和之后的安装方式是不一样的。首先保证3306端口的可用或者关闭防火墙两台机子可以互相ping二、Master的配置1.修改MySQL配置文件[[email protected] ~]# vim /etc/my.cnf文件内容[mysqld]#开启二进制日志log-binmysql-bin#标识唯一id(必须)一般使用ip最后位server-id2#不同步的数据库可设置多个binlog-ignore-dbinformation_schemabinlog-ignore-dbclusterbinlog-ignore-dbmysql#指定需要同步的数据库(和slave是相互匹配的)可以设置多个binlog-do-dbtest2.重启MySQLservice mysqld restart3.进去mysql设置允许从库获得主库日志 注这里使用root用户配置不建议使用[[email protected] ~]# mysql -u root -p#给从库放权限mysqlGRANT FILE ON *.* TO [email protected] IDENTIFIED BY ‘root password‘;mysqlGRANT REPLICATION SLAVE ON *.* TO [email protected] IDENTIFIED BY ‘root password‘;mysqlFLUSH PRIVILEGES;4.重启MySQL登录MySQL查看主库信息mysql show master status;显示内容-----------------------------------------------------------------------------------------------| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |-----------------------------------------------------------------------------------------------| mysql-bin.000006 | 120 | ufind_db | information_schema,cluster,mysql | |-----------------------------------------------------------------------------------------------1 row in set (0.00 sec)mysql注如果执行这个步骤始终为Empty set(0.00 sec)那说明前面的my.cnf没配置对三、Slave的配置1.从库配置#开启二进制日志(可以不配置)log-binmysql-binserver-id3binlog-ignore-dbinformation_schemabinlog-ignore-dbclusterbinlog-ignore-dbmysql#与主库配置一直replicate-do-dbtestreplicate-ignore-dbmysqllog-slave-updatesslave-skip-errorsallslave-net-timeout604.重启MySQL登录MySQL#关闭Slavemysql stop slave;#设置连接主库信息mysql change master to master_host‘192.168.2.1‘,master_user‘root‘,master_password‘root password‘,master_log_file‘mysql-bin.000006‘, master_log_pos120;#开启Slavemysql start slave;注上面的master_log_file是在配置Master的时候的File字段 master_log_pos是在配置Master的Position 字段。一定要一一对应5.查看信息mysql show slave status \G;*************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: 192.168.2.1Master_User: rootMaster_Port: 3306Connect_Retry: 60Master_Log_File: mysql-bin.000006Read_Master_Log_Pos: 120Relay_Log_File: localhost-relay-bin.000006Relay_Log_Pos: 520Relay_Master_Log_File: mysql-bin.000006Slave_IO_Running: Yes //显示yes为成功Slave_SQL_Running: Yes //显示yes为成功如果为no一般为没有启动masterReplicate_Do_DB: testReplicate_Ignore_DB: mysql//上面的都是配置文件中的信息Replicate_Do_Table:Replicate_Ignore_Table:Replicate_Wild_Do_Table:Replicate_Wild_Ignore_Table:Last_Errno: 0Last_Error:Skip_Counter: 0Exec_Master_Log_Pos: 357Relay_Log_Space: 697Until_Condition: NoneUntil_Log_File:Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_SSL_CA_File:Master_SSL_CA_Path:Master_SSL_Cert:Master_SSL_Cipher:Master_SSL_Key:Seconds_Behind_Master: 0Master_SSL_Verify_Server_Cert: NoLast_IO_Errno: 0Last_IO_Error: //如果为no此处会显示错误信息Last_SQL_Errno: 0Last_SQL_Error:Replicate_Ignore_Server_Ids:Master_Server_Id: 2Master_UUID: be0a41c0-2b40-11e8-b791-000c29267b6aMaster_Info_File: /usr/local/mysql/data/master.infoSQL_Delay: 0SQL_Remaining_Delay: NULLSlave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update itMaster_Retry_Count: 86400Master_Bind:Last_IO_Error_Timestamp:Last_SQL_Error_Timestamp:Master_SSL_Crl:Master_SSL_Crlpath:Retrieved_Gtid_Set:Executed_Gtid_Set:Auto_Position: 01 row in set (0.00 sec)ERROR:No query specified注如果Slave_IO_Running: No 出现下面的错误Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work.说明主服务器的UUID和从服务器的UUID重复更改方式[[email protected] ~]# vim /usr/local/mysql/data/auto.cnf #这是我的安装路径修改auto.cnf的server-uuid以上主从MySQL已经可以使用了欢迎各位多提bug