日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mariadb mysql同步_CentOS7安装配置MariaDB(mysql)数据主从同步

發布時間:2025/3/15 数据库 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mariadb mysql同步_CentOS7安装配置MariaDB(mysql)数据主从同步 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

CentOS7安裝MariaDB并配置主從同步

環境聲明:

防火墻firewalld及SElinux均為關閉狀態

主庫節點:192.168.0.63

從庫節點:192.168.0.64

配置主庫節點:

前提:配置好yum軟件安裝源

yum install mariadb-server

vim /etc/my.cnf

主庫節點mariadb配置文件/etc /my.cnd

[mysqld]

binlog-ignore-db=mysql

binlog-ignore-db=information_schema

log-bin=mysql-bin

server-id=1

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

# 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

配置文件補充說明:

binlog-ignore-db 用來指定忽略同步的數據庫,未指定的默認都進行主從復制。

log-bin 指定數據庫操作日志,主從復制的過程本質就是從數據庫在主數據庫讀取該日志,并且再執行一次。

server-id 只要滿足在數據庫集群中不重復即可且必須不能重復

保存退出,重啟Mysqld服務,使配置生效。修改到配置文件,最好都重啟該配置相關的程序或服務。

systemctl start mariadb

systemctl enable mariadb

mysql_secure_installation

Enter current password for root (enter for none): # 輸入數據庫超級管理員root的密碼(注意不是系統root的密碼),第一次進入還沒有設置密碼則直接回車

Set root password? [Y/n] # 設置密碼,y

New password: # 新密碼

Re-enter new password: # 再次輸入密碼

Remove anonymous users? [Y/n] # 移除匿名用戶, y

Disallow root login remotely? [Y/n] # 拒絕root遠程登錄,n,不管y/n,都會拒絕root遠程登錄

Remove test database and access to it? [Y/n] # 刪除test數據庫,y:刪除。n:不刪除,數據庫中會有一個test數據庫,一般不需要

Reload privilege tables now? [Y/n] # 重新加載權限表,y?;蛘咧貑⒎找苍S

MariaDB [(none)]> show master status\G

*************************** 1. row ***************************

File: mysql-bin.000003 # slave根據此信息進行數據同步

Position: 1208 # slave根據此信息進行數據同步

Binlog_Do_DB:

Binlog_Ignore_DB: mysql,information_schema

1 row in set (0.00 sec)

MariaDB [(none)]>

MariaDB [(none)]> GRANT REPLICATION SLAVE ON . to 'slave'@'192.168.0.64' identified by 'root'

-> ;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON . TO 'root'@'192.168.0.63' IDENTIFIED BY 'root' WITH GRANT OPTION;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON . TO 'root'@'192.168.0.64' IDENTIFIED BY 'root' WITH GRANT OPTION;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> quit

Bye

[root@cosmo-0-63 yum.repos.d]# systemctl restart mariadb

至此主庫配置完畢

配置從庫節點:

安裝步驟和主庫一樣

配置文件修改

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

server-id=2 # 添加此行

# 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

然后重啟mariadb,進行登陸

執行sql語句:change master to master_host='192.168.0.63',master_user='slave',master_password='root',master_log_file='mysql-bin.000003',master_log_pos=1208;

MariaDB [(none)]> change master to master_host='192.168.0.63',master_user='slave',master_password='root',master_log_file='mysql-bin.000003',master_log_pos=1208;

MariaDB [(none)]> slave start;

Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show slave status\G

*************************** 1. row ***************************

Slave_IO_State: Connecting to master

Master_Host: 192.168.0.63

Master_User: slave

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000003

Read_Master_Log_Pos: 1208

Relay_Log_File: mariadb-relay-bin.000001

Relay_Log_Pos: 4

Relay_Master_Log_File: mysql-bin.000003

Slave_IO_Running: Connecting

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: 1208

Relay_Log_Space: 245

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: NULL

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: 0

1 row in set (0.00 sec)

只有當Slave_IO_Running和Slave_SQL_Running都顯示Yes時,才表示主從復制配置成功。否則失敗,檢查上述配置過程。

主從復制驗證:

首先,在主數據建立一個demo數據庫,看兩個從數據庫是否會自動進行復制。

在服務器A登錄主數據庫,查看現有數據庫。

63主庫節點:

MariaDB [(none)]> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

+--------------------+

3 rows in set (0.00 sec)

MariaDB [(none)]> create database demo;

Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| demo |

| mysql |

| performance_schema |

+--------------------+

4 rows in set (0.00 sec)

然后登陸64節點進行查看

能看到在63上創建的demo庫則代表配置主從成功

MariaDB [(none)]> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| demo |

| mysql |

| performance_schema |

+--------------------+

4 rows in set (0.00 sec)

THE END

總結

以上是生活随笔為你收集整理的mariadb mysql同步_CentOS7安装配置MariaDB(mysql)数据主从同步的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。