[root@localhost ~]# cat /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock `# 新添加的部分 # 配置主从时需要添加以下信息 start innodb_file_per_table=NO log-bin=/var/lib/mysql/master-bin #log-bin没指定存储目录,则是默认datadir指向的目录 binlog_format=mixed server-id=200 #每个服务器都需要添加server_id配置,各个服务器的server_id需要保证唯一性,实践中通常设置为服务器IP地址的最后一位 #配置主从时需要添加以下信息 end ` # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid # # include all files from the config directory # !includedir /etc/my.cnf.d
[root@localhost ~]# systemctl restart mariadb.service
[root@localhost ~]# mysql -u root -padmin
MariaDB [(none)]> GRANT REPLICATION SLAVE ON *.* TO 'root'@'10.69.5.%' IDENTIFIED BY 'admin'; Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> FLUSH TABLES WITH READ LOCK; Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> SHOW MASTER STATUS; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000001 | 694 | | | +------------------+----------+--------------+------------------+
[root@localhost ~]# mysqldump -uroot -p --all-databases > /root/db.sql
MariaDB [(none)]> UNLOCK TABLES; Query OK, 0 rows affected (0.00 sec)
[root@localhost ~]# mysql -uroot -p < db.sql
[root@localhost ~]# cat /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 `#配置主从时需要添加以下信息 start innodb_file_per_table=NO server-id=201 #一般与服务器ip的最后数字一致 relay-log=/var/lib/mysql/relay-bin #配置主从时需要添加以下信息 end ` # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe] log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pid # # include all files from the config directory # !includedir /etc/my.cnf.d
[root@localhost ~]# systemctl restart mariadb.service
[root@localhost ~]# mysql -u root -padmin
MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST='10.69.5.200',MASTER_USER='root', MASTER_PASSWORD='admin', MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS= 694; Query OK, 0 rows affected (0.02 sec)
MariaDB [(none)]> START SLAVE; Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.69.5.200
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000001
Read_Master_Log_Pos: 694
Relay_Log_File: relay-bin.000003
Relay_Log_Pos: 530
Relay_Master_Log_File: master-bin.000001
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: 694
Relay_Log_Space: 818
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:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 200
1 row in set (0.00 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| mytest |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.04 sec)
MariaDB [(none)]> use mytest;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [mytest]> select * from user;
+----+------+
| id | name |
+----+------+
| 1 | t |
| 2 | t2 |
| 3 | t3 |
+----+------+
3 rows in set (0.00 sec)
MariaDB [mytest]> insert into user(name) values('t4');
Query OK, 1 row affected (0.01 sec)
MariaDB [mytest]> select * from user;
+----+------+
| id | name |
+----+------+
| 1 | t |
| 2 | t2 |
| 3 | t3 |
| 4 | t4 |
+----+------+
4 rows in set (0.00 sec)
MariaDB [(none)]> use mytest; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed MariaDB [mytest]> select * from user; +----+------+ | id | name | +----+------+ | 1 | t | | 2 | t2 | +----+------+ 2 rows in set (0.00 sec) MariaDB [mytest]> select * from user; +----+------+ | id | name | +----+------+ | 1 | t | | 2 | t2 | | 4 | t4 | +----+------+ 3 rows in set (0.00 sec)
MariaDB [mytest]> start slave; ERROR 1201 (HY000): Could not initialize master info structure; more error messages can be found in the MariaDB error log
Slave_IO_Running: No Slave_SQL_Running: No
[root@localhost ~]# cat /var/log/mariadb/mariadb.log 160915 12:52:02 [ERROR] Failed to open the relay log './mariadb-relay-bin.000001' (relay_log_pos 4) 160915 12:52:02 [ERROR] Could not find target log during relay log initialization
[root@localhost mysql]# mysql -u root -padmin MariaDB [(none)]> flush logs; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> reset slave; Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST='10.69.5.200',MASTER_USER='root', MASTER_PASSWORD='admin', MASTER_LOG_FILE='master-bin.000001', MASTER_LOG_POS= 694; Query OK, 0 rows affected (0.02 sec)
MariaDB [(none)]> start slave; Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Connecting to master
Master_Host: 10.69.5.200
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master-bin.000001
Read_Master_Log_Pos: 694
Relay_Log_File: relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: master-bin.000001
Slave_IO_Running: Connecting
Slave_SQL_Running: Yes
···
···
···
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0
1 row in set (0.00 sec)
[root@localhost ~]# cat /var/log/mariadb/mariadb.log ··· 160915 13:17:56 [Note] Slave SQL thread initialized, starting replication in log 'master-bin.000001' at position 694, relay log '/var/lib/mysql/relay-bin.000001' position: 4 160915 13:17:56 [ERROR] Slave I/O: error connecting to master 'root@10.69.5.200:3306' - retry-time: 60 retries: 86400 message: Can't connect to MySQL server on '10.69.5.200' (113), Error_code: 2003
[root@localhost ~]# telnet 10.69.5.200 3306
[root@localhost ~]# yum -y install telnet-server.x86_64
[root@localhost ~]# systemctl start telnet.socket [root@localhost ~]# systemctl enable telnet.socket [root@localhost ~]# telnet 10.69.5.200 3306
[root@localhost ~]# yum install telnet.x86_64
[root@localhost ~]# systemctl enable telnet.socket [root@localhost ~]# systemctl start telnet.socket [root@localhost ~]# firewall-cmd --add-service=telnet --permanent success [root@localhost ~]# telnet telnet>
yum install mariadb mariadb-server
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有