12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
ADADADADAD
mysql数据库 时间:2024-12-24 19:13:11
作者:文/会员上传
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
主从配置过程:参看:https://mariadb.com/kb/en/library/setting-up-replication/https://dev.mysql.com/doc/refman/5.5/en/replication-configuration.html主服务器192.168.2
以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。
主从配置过程:参看:https://mariadb.com/kb/en/library/setting-up-replication/https://dev.mysql.com/doc/refman/5.5/en/replication-configuration.html
主服务器192.168.27.7配置:
[root@master~]$vim/etc/my.cnf[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sock#Disablingsymbolic-linksisrecommendedtopreventassortedsecurityriskssymbolic-links=0innodb_file_per_tablelog_binserver-id=1[root@master~]$systemctlstartmariadb.serviceMariaDB[(none)]>showbinarylogs;+--------------------+-----------+|Log_name|File_size|+--------------------+-----------+|mariadb-bin.000001|245|+--------------------+-----------+1rowinset(0.00sec)[root@master~]$mysql<hellodb_InnoDB.sqlMariaDB[(none)]>showbinarylogs;+--------------------+-----------+|Log_name|File_size|+--------------------+-----------+|mariadb-bin.000001|7655|+--------------------+-----------+1rowinset(0.00sec)MariaDB[(none)]>grantreplicationslaveon*.*torepluser@'192.168.27.%'identifiedby'centos';QueryOK,0rowsaffected(0.00sec)
从服务器192.168.27.17服务配置:
从服务器上的配置:[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sock#Disablingsymbolic-linksisrecommendedtopreventassortedsecurityriskssymbolic-links=0#Settingsuserandgroupareignoredwhensystemdisused.innodb_file_per_tableserver_id=2注意:默认的server_id是0;MariaDB[(none)]>showvariableslike'server_id';+---------------+-------+|Variable_name|Value|+---------------+-------+|server_id|0|+---------------+-------+1rowinset(0.01sec)查看帮助:MariaDB[(none)]>helpchangemasterto;CHANGEMASTERTOMASTER_HOST='master2.mycompany.com',MASTER_USER='replication',MASTER_PASSWORD='bigs3cret',MASTER_PORT=3306,MASTER_LOG_FILE='master2-bin.001',MASTER_LOG_POS=4,MASTER_CONNECT_RETRY=10;MariaDB[(none)]>CHANGEMASTERTO->MASTER_HOST='192.168.27.7',->MASTER_USER='repluser',->MASTER_PASSWORD='centos',->MASTER_PORT=3306,->MASTER_LOG_FILE='mariadb-bin.000001',->MASTER_LOG_POS=245,->MASTER_CONNECT_RETRY=10;QueryOK,0rowsaffected(0.02sec)MariaDB[(none)]>showslavestatus\G***************************1.row***************************Slave_IO_State:Master_Host:192.168.27.7Master_User:repluserMaster_Port:3306Connect_Retry:10Master_Log_File:mariadb-bin.000001Read_Master_Log_Pos:245Relay_Log_File:mariadb-relay-bin.000001Relay_Log_Pos:4Relay_Master_Log_File:mariadb-bin.000001Slave_IO_Running:No线程未启动;Slave_SQL_Running:No线程未启动;Replicate_Do_DB:Replicate_Ignore_DB:Replicate_Do_Table:Replicate_Ignore_Table:Replicate_Wild_Do_Table:Replicate_Wild_Ignore_Table:Last_Errno:0Last_Error:Skip_Counter:0Exec_Master_Log_Pos:245复制的起始位置;Relay_Log_Space:245Until_Condition:NoneUntil_Log_File:Until_Log_Pos:0Master_SSL_Allowed:No可以启用加密;Master_SSL_CA_File:Master_SSL_CA_Path:Master_SSL_Cert:Master_SSL_Cipher:Master_SSL_Key:Seconds_Behind_Master:NULLMaster_SSL_Verify_Server_Cert:NoLast_IO_Errno:0Last_IO_Error:Last_SQL_Errno:0Last_SQL_Error:Replicate_Ignore_Server_Ids:Master_Server_Id:01rowinset(0.00sec)
中继日志已经创建;[root@centos7x~]$ll/var/lib/mysql/total28724-rw-rw----1mysqlmysql16384Feb2506:37aria_log.00000001-rw-rw----1mysqlmysql52Feb2506:37aria_log_control-rw-rw----1mysqlmysql18874368Feb2506:37ibdata1-rw-rw----1mysqlmysql5242880Feb2506:37ib_logfile0-rw-rw----1mysqlmysql5242880Feb2505:09ib_logfile1-rw-rw----1mysqlmysql264Feb2505:15mariadb-bin.000001-rw-rw----1mysqlmysql21Feb2505:10mariadb-bin.index-rw-rw----1mysqlmysql245Feb2506:38mariadb-relay-bin.000001-rw-rw----1mysqlmysql27Feb2506:38mariadb-relay-bin.index-rw-rw----1mysqlmysql84Feb2506:38master.infodrwx------2mysqlmysql4096Feb2505:09mysqlsrwxrwxrwx1mysqlmysql0Feb2506:37mysql.sockdrwx------2mysqlmysql4096Feb2505:09performance_schema-rw-rw----1mysqlmysql52Feb2506:38relay-log.infodrwx------2mysqlmysql6Feb2505:09test
启动从服务器上的复制线程:
MariaDB[(none)]>startslave;ERROR2006(HY000):MySQLserverhasgoneawayNoconnection.Tryingtoreconnect...Connectionid:4Currentdatabase:***NONE***QueryOK,0rowsaffected,1warning(0.00sec)MariaDB[(none)]>showdatabases;+--------------------+|Database|+--------------------+|information_schema||hellodb||mysql||performance_schema||test|+--------------------+MariaDB[(none)]>showslavestatus\G***************************1.row***************************Slave_IO_State:WaitingformastertosendeventMaster_Host:192.168.27.7Master_User:repluserMaster_Port:3306Connect_Retry:60Master_Log_File:mariadb-bin.000002Read_Master_Log_Pos:245读取的日志的位置;Relay_Log_File:mariadb-relay-bin.000005Relay_Log_Pos:531Relay_Master_Log_File:mariadb-bin.000002Slave_IO_Running:YesSlave_SQL_Running:YesReplicate_Do_DB:Replicate_Ignore_DB:Replicate_Do_Table:Replicate_Ignore_Table:Replicate_Wild_Do_Table:Replicate_Wild_Ignore_Table:Last_Errno:0Last_Error:Skip_Counter:0Exec_Master_Log_Pos:245执行的日志的位置;Relay_Log_Space:1113Until_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:0落后的时间差;Master_SSL_Verify_Server_Cert:NoLast_IO_Errno:0Last_IO_Error:Last_SQL_Errno:0Last_SQL_Error:Replicate_Ignore_Server_Ids:Master_Server_Id:11rowinset(0.00sec)
主服务器的读写操作:
主服务器的日志位置;MariaDB[(none)]>showmasterlogs;+--------------------+-----------+|Log_name|File_size|+--------------------+-----------+|mariadb-bin.000001|8217||mariadb-bin.000002|245|+--------------------+-----------+2rowsinset(0.00sec)主服务器的写:MariaDB[(none)]>createdatabasewangdb;QueryOK,1rowaffected(0.00sec)MariaDB[(none)]>showmasterlogs;+--------------------+-----------+|Log_name|File_size|+--------------------+-----------+|mariadb-bin.000001|8217||mariadb-bin.000002|332|+--------------------+-----------+2rowsinset(0.00sec)MariaDB[(none)]>showslavestatus\G***************************1.row***************************Slave_IO_State:WaitingformastertosendeventMaster_Host:192.168.27.7Master_User:repluserMaster_Port:3306Connect_Retry:60Master_Log_File:mariadb-bin.000002Read_Master_Log_Pos:332Relay_Log_File:mariadb-relay-bin.000003Relay_Log_Pos:618Relay_Master_Log_File:mariadb-bin.000002Slave_IO_Running:YesSlave_SQL_Running:YesReplicate_Do_DB:Replicate_Ignore_DB:Replicate_Do_Table:Replicate_Ignore_Table:Replicate_Wild_Do_Table:Replicate_Wild_Ignore_Table:Last_Errno:0Last_Error:Skip_Counter:0Exec_Master_Log_Pos:332Relay_Log_Space:9153Until_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:Last_SQL_Errno:0Last_SQL_Error:Replicate_Ignore_Server_Ids:Master_Server_Id:11rowinset(0.00sec)
从服务器:
从服务器瞬间同步:MariaDB[(none)]>showdatabases;+--------------------+|Database|+--------------------+|information_schema||hellodb||mysql||performance_schema||test||wangdb|+--------------------+6rowsinset(0.00sec)停止从服务器;并在主服务器上更新操作;MariaDB[(none)]>createdatabasewangdb2;QueryOK,1rowaffected(0.00sec)MariaDB[(none)]>createdatabasewangdb3;QueryOK,1rowaffected(0.00sec)从服务器;[root@centos7x~]$systemctlstopmariadb.service[root@centos7x~]$[root@centos7x~]$[root@centos7x~]$systemctlstartmariadb.serviceunknown[(none)]>showdatabases;Noconnection.Tryingtoreconnect...Connectionid:4Currentdatabase:***NONE***+--------------------+|Database|+--------------------+|information_schema||hellodb||mysql||performance_schema||test||wangdb||wangdb2||wangdb3|+--------------------+8rowsinset(0.00sec)从服务器上的relay-log.info记录的是[root@centos7x~]$ls/var/lib/mysql/aria_log.00000001ibdata1mariadb-relay-bin.000004master.infoperformance_schemawangdbaria_log_controlib_logfile0mariadb-relay-bin.000005mysqlrelay-log.infowangdb2hellodbib_logfile1mariadb-relay-bin.indexmysql.socktestwangdb3[root@centos7x~]$[root@centos7x~]$cat/var/lib/mysql/relay-log.info./mariadb-relay-bin.000005709mariadb-bin.0000025108[root@centos7x~]$cat/var/lib/mysql/master.info18mariadb-bin.000002510192.168.27.7replusercentos330660001800.0000主服务器;MariaDB[(none)]>showmasterlogs;+--------------------+-----------+|Log_name|File_size|+--------------------+-----------+|mariadb-bin.000001|8217||mariadb-bin.000002|510|+--------------------+-----------+2rowsinset(0.00sec)
11-20
11-19
11-20
11-20
11-20
11-19
11-20
11-20
11-19
11-20
11-19
11-19
11-19
11-19
11-19
11-19