mysql主從
目錄- mysql主從
- 1.主從原理
- 1.1 主從介紹
- 1.2 主從作用
- 1.3 主從形式
- 1.4 主從復制原理
- 2.主從復制配置
- 2.1 mysql安裝
- 2.2 mysql主從配置
- 2.2.1 確保從資料庫于主資料庫的資料一樣
- 2.2.2 在主資料庫里創建一個同步賬號授權給從資料庫使用
- 2.2.3 配置主資料庫
- 2.2.4 配置從資料庫
- 2.2.5 測驗驗證
- 3.GTID主從
- 3.1 GTID概念介紹
- 3.2 GTID作業原理
- 3.3 GTID主從配置
- 3.3.1 主庫配置,并重啟mysql
- 3.3.2 從庫配置,并重啟mysql
- 3.3.3 主庫授權復制用戶
- 3.3.4 從庫設定要同步的主庫資訊,并開啟同步
- 3.3.5 測驗驗證
- 1.主從原理
1.主從原理
1.1 主從介紹
所謂mysql主從就是建立兩個完全一樣的資料庫,其中一個為主要使用的資料庫,另一個為次要的資料庫,一般在企業中,存放比較重要的資料的資料庫服務器需要配置主從,這樣可以防止因資料庫服務器宕機導致資料丟失,還能保證業務量太多、資料太多和訪問人數太多時服務的質量(服務器回應速度),還能提供故障切換、讀寫分離、和備份等等功能
1.2 主從作用
- 實時災備,用于故障切換
- 讀寫分離,提供查詢服務
- 備份,避免影響業務
1.3 主從形式

一主一從
主主復制:當作備份使用,當主服務器出現故障時,另一個主服務器會自動頂上,
一主多從:用來實作讀寫分離,當寫操作較少時,讀操作較多時使用,主服務器用來實作寫操作,從服務器用來實作讀操作,
多主一從:用來實作讀寫分離,當寫操作較多時,讀操作較少時使用,主服務器用來實作寫操作,從服務器用來實作讀操作,5.7開始支持
聯級復制:是指從主場地復制過來的又從該場地再次復制到其他場地,即A場地把資料復制到B場地,B場地又把這些資料或其中部分資料再復制到其他場地,
1.4 主從復制原理

主從復制步驟:
- 主庫將所有的寫操作記錄到binlog日志中并生成一個log dump執行緒,將binlog日志傳給從庫的I/O執行緒
- 從庫生成兩個執行緒,一個I/O執行緒,一個SQL執行緒
- I/O執行緒去請求主庫的binlog,并將得到的binlog日志寫到relay log(中繼日志) 檔案中
- SQL執行緒,會讀取relay log檔案中的日志,并決議成具體操作,來實作主從的操作一致,達到最終資料一致的目的
2.主從復制配置
主從復制配置步驟:
- 確保從資料庫與主資料庫里的資料一樣
- 在主資料庫里創建一個同步賬號授權給從資料庫使用
- 配置主資料庫(修改組態檔)
- 配置從資料庫(修改組態檔)
需求:
搭建兩臺MySQL服務器,一臺作為主服務器,一臺作為從服務器,主服務器進行寫操作,從服務器進行讀操作
環境說明:
| 資料庫角色 | IP | 應用與系統版本 | 有無資料 |
|---|---|---|---|
| 主資料庫 | 192.168.111.135 | centos8/redhat8 mysql-5.7 | 有資料 |
| 從資料庫 | 192.168.111.137 | centos8/redhat8 mysql-5.7 | 無資料 |
2.1 mysql安裝
分別在主從兩臺服務器上安裝mysql-5.7版本
[root@localhost ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
[root@localhost ~]# rpm -Uvh mysql57-community-release-el7-11.noarch.rpm
[root@localhost ~]# yum module disable mysql //禁用mysql
[root@localhost ~]# yum -y install mysql-community-server mysql-community-client mysql-community-common mysql-community-devel --nogpgcheck
//安裝完后設定開機自啟動
[root@localhost ~]# systemctl enable --now mysqld
//在日志中找出密碼
[root@localhost ~]# grep "password" /var/log/mysqld.log
2022-07-25T06:34:28.883599Z 1 [Note] A temporary password is generated for root@localhost: OFU+amdhV3Wr //臨時密碼
//關閉防火墻和selinux
[root@localhost ~]# systemctl disable --now firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# vim /etc/selinux/config
SELINUX=disabled
//使用臨時密碼登錄mysql
[root@localhost ~]# mysql -uroot -pOFU+amdhV3Wr //-p后可以跟密碼
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.38
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> //看到這樣的標識表示登錄進去了
//修改mysql登錄密碼
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)
//為避免mysql自動升級,需要卸載最開始安裝的yum源
[root@localhost ~]# rpm -e mysql57-community-release
2.2 mysql主從配置
2.2.1 確保從資料庫于主資料庫的資料一樣
為確保從資料庫與主資料庫里的資料一樣,先全備主資料庫并還原到從資料庫中
//主庫為master
[root@localhost ~]# hostnamectl set-hostname master
[root@localhost ~]# bash
[root@master ~]#
//從庫為slave
[root@localhost ~]# hostnamectl set-hostname slave
[root@localhost ~]# bash
[root@slave ~]#
//先查看主庫有哪些庫
[root@master ~]# mysql -uroot -p123456 -e'show databases;'
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| runtime |
| sys |
+--------------------+
//在查看從庫
[root@slave ~]# mysql -uroot -p123456 -e'show databases;'
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
//全備主庫
//全備主庫時需要另開一個終端,給資料庫加上讀鎖,避免在備份期間有其他人在寫入導致資料不一致
mysql> FLUSH TABLES WITH READ LOCK;
Query OK, 0 rows affected (0.00 sec)
//此鎖表的終端必須在備份完成以后才能退出
//備份主庫并將備份檔案傳送到從庫
[root@master ~]# mysqldump -uroot -p123456 --all-databases > /opt/all-2022.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
[root@master ~]# ls /opt/
all-2022.sql
[root@master ~]# scp /opt/all-2022.sql [email protected]:/opt/
The authenticity of host '192.168.111.137 (192.168.111.137)' can't be established.
ECDSA key fingerprint is SHA256:AneDLcALQuLH7WhrvDCtu+7mdCXjrXa87i7CQ+01ntk.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.111.137' (ECDSA) to the list of known hosts.
[email protected]'s password:
all-2022.sql 100% 860KB 110.1MB/s 00:00
//解除主庫的鎖表狀態,直接退出互動式界面即可
mysql> quit
Bye
[root@master ~]#
//在從庫上恢復主庫的備份并查看從庫有哪些庫,確保與主庫一致
[root@slave ~]# mysql -uroot -p123456 < /opt/all-2022.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@slave ~]# mysql -uroot -p123456 -e'show databases;'
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| runtime |
| sys |
+--------------------+
2.2.2 在主資料庫里創建一個同步賬號授權給從資料庫使用
mysql> create user 'repl'@'192.168.111.137' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> grant replication slave on *.* to 'repl'@'192.168.111.137';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
2.2.3 配置主資料庫
[root@master ~]# vim /etc/my.cnf
//在[mysql]這段后面添加
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-bin=mysql-bin //添加 啟用binlog日志
server-id=1 //添加 資料庫服務器唯一識別符號,主庫的server-id值必須比從庫的小
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
//重啟數主庫的mysql服務
[root@master ~]# systemctl restart mysqld
[root@master ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 [::]:22 [::]:*
//查看主庫的狀態
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 | 154 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
2.2.4 配置從資料庫
[root@slave ~]# vim /etc/my.cnf
//在[mysql]這段后面添加
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
server-id=2 //添加 從庫的server-id比主庫的大
relay-log=mysql-relay-bin //添加
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
//重啟mysql服務
[root@slave ~]# systemctl restart mysqld
[root@slave ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 [::]:22 [::]:*
//配置并啟動主從復制
mysql> change master to
-> master_host='192.168.111.135',
-> master_user='repl',
-> master_password='123456',
-> master_log_file='mysql-bin.000001',
-> master_log_pos=154;
Query OK, 0 rows affected, 2 warnings (0.01 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
//查看服務器狀態
mysql> show slave status \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.111.135
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 154
Relay_Log_File: mysql-relay-bin.000002
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes //此處只許為yes
Slave_SQL_Running: Yes //此處只許為yes
Replicate_Do_DB:
Replicate_Ignore_DB:
2.2.5 測驗驗證
在主服務器的runtime庫的zxr表中插入資料
mysql> use runtime;
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
mysql> select * from zxr;
Empty set (0.00 sec)
mysql> insert into zxr values (1,'sean',20),(2,'tom',23),(3,'jerry',30);
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from zxr;
+----+-------+------+
| id | name | age |
+----+-------+------+
| 1 | sean | 20 |
| 2 | tom | 23 |
| 3 | jerry | 30 |
+----+-------+------+
3 rows in set (0.00 sec)
在從資料庫中查看資料是否同步
mysql> use runtime;
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
mysql> select * from zxr;
+----+-------+------+
| id | name | age |
+----+-------+------+
| 1 | sean | 20 |
| 2 | tom | 23 |
| 3 | jerry | 30 |
+----+-------+------+
3 rows in set (0.00 sec)
3.GTID主從
3.1 GTID概念介紹
GTID即全域事務ID (global transaction identifier), 其保證為每一個在主上提交的事務在復制集群中可以生成一個唯一的ID,GTID最初由google實作,官方MySQL在5.6才加入該功能,mysql主從結構在一主一從情況下對于GTID來說就沒有優勢了,而對于2臺主以上的結構優勢例外明顯,可以在資料不丟失的情況下切換新主,使用GTID需要注意: 在構建主從復制之前,在一臺將成為主的實體上進行一些操作(如資料清理等),通過GTID復制,這些在主從成立之前的操作也會被復制到從服務器上,引起復制失敗,也就是說通過GTID復制都是從最先開始的事務日志開始,即使這些操作在復制之前執行,比如在server1上執行一些drop、delete的清理操作,接著在server2上執行change的操作,會使得server2也進行server1的清理操作,
GTID實際上是由UUID+TID (即transactionId)組成的,其中UUID(即server_uuid) 產生于auto.conf檔案(cat /data/mysql/data/auto.cnf),是一個MySQL實體的唯一標識,TID代表了該實體上已經提交的事務數量,并且隨著事務提交單調遞增,所以GTID能夠保證每個MySQL實體事務的執行(不會重復執行同一個事務,并且會補全沒有執行的事務),GTID在一組復制中,全域唯一, 下面是一個GTID的具體形式 :
mysql> show master status;
+------------------+----------+--------------+------------------+------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+------------------------------------------+
| mysql_bin.000001 | 1114 | | | a190ac61-117c-11ed-abda-000c296d5362:1-4 |
+------------------+----------+--------------+------------------+------------------------------------------+
1 row in set (0.00 sec)
GTID=a190ac61-117c-11ed-abda-000c296d5362:1-4
UUID=a190ac61-117c-11ed-abda-000c296d5362
transactionId:1-4
了解了GTID的格式,通過UUID可以知道這個事務在哪個實體上提交的,通過GTID可以極方便的進行復制結構上的故障轉移,新主設定,這就很好地解決了下面這個圖所展現出來的問題,

如圖, Server1(Master)崩潰,根據從上show slave status獲得Master_log_File/Read_Master_Log_Pos的值,Server2(Slave)已經跟上了主,Server3(Slave)沒有跟上主,這時要是把Server2提升為主,Server3變成Server2的從,這時在Server3上執行change的時候需要做一些計算,
這個問題在5.6的GTID出現后,就顯得非常的簡單,由于同一事務的GTID在所有節點上的值一致,那么根據Server3當前停止點的GTID就能定位到Server2上的GTID,甚至由于MASTER_AUTO_POSITION功能的出現,我們都不需要知道GTID的具體值,直接使用CHANGE MASTER TO MASTER_HOST='xxx', MASTER_AUTO_POSITION命令就可以直接完成failover的作業,
====== GTID和Binlog的關系 ======
- GTID在binlog中的結構

- GTID event 結構

- Previous_gtid_log_event
Previous_gtid_log_event 在每個binlog 頭部都會有每次binlog rotate的時候存盤在binlog頭部Previous-GTIDs在binlog中只會存盤在這臺機器上執行過的所有binlog,不包括手動設定gtid_purged值,換句話說,如果你手動set global gtid_purged=xx; 那么xx是不會記錄在Previous_gtid_log_event中的, - GTID和Binlog之間的關系是怎么對應的呢? 如何才能找到GTID=? 對應的binlog檔案呢?
假設有4個binlog: bin.001,bin.002,bin.003,bin.004
bin.001 : Previous-GTIDs=empty; binlog_event有: 1-40
bin.002 : Previous-GTIDs=1-40; binlog_event有: 41-80
bin.003 : Previous-GTIDs=1-80; binlog_event有: 81-120
bin.004 : Previous-GTIDs=1-120; binlog_event有: 121-160
假設現在我們要找GTID=$A,那么MySQL的掃描順序為: - 從最后一個binlog開始掃描(即: bin.004)
- bin.004的Previous-GTIDs=1-120,如果$A=140 > Previous-GTIDs,那么肯定在bin.004中
- bin.004的Previous-GTIDs=1-120,如果$A=88 包含在Previous-GTIDs中,那么繼續對比上一個binlog檔案 bin.003,然后再回圈前面2個步驟,直到找到為止.
====== GTID 重要引數的持久化 =======
- GTID相關引數
| 引數 | comment |
|---|---|
| gtid_executed | 執行過的所有GTID |
| gtid_purged | 丟棄掉的GTID |
| gtid_mode | GTID模式 |
| gtid_next | session級別的變數,下一個gtid |
| gtid_owned | 正在運行的GTID |
| enforce_gtid_consistency | 保證GTID安全的引數 |
開啟GTID的必備條件
gtid_mode=on (必選)
enforce-gtid-consistency=1 (必選)
log_bin=mysql-bin (可選) #高可用切換,最好開啟該功能
log-slave-updates=1 (可選) #高可用切換,最好打開該功能
3.2 GTID作業原理
從服務器連接到主服務器之后,把自己執行過的GTID (Executed_Gtid_Set: 即已經執行的事務編碼) 、獲取到的GTID (Retrieved_Gtid_Set: 即從庫已經接收到主庫的事務編號) 發給主服務器,主服務器把從服務器缺少的GTID及對應的transactions發過去補全即可,當主服務器掛掉的時候,找出同步最成功的那臺從服務器,直接把它提升為主即可,如果硬要指定某一臺不是最新的從服務器提升為主, 先change到同步最成功的那臺從服務器, 等把GTID全部補全了,就可以把它提升為主了,
GTID是MySQL 5.6的新特性,可簡化MySQL的主從切換以及Failover,GTID用于在binlog中唯一標識一個事務,當事務提交時,MySQL Server在寫binlog的時候,會先寫一個特殊的Binlog Event,型別為GTID_Event,指定下一個事務的GTID,然后再寫事務的Binlog,主從同步時GTID_Event和事務的Binlog都會傳遞到從庫,從庫在執行的時候也是用同樣的GTID寫binlog,這樣主從同步以后,就可通過GTID確定從庫同步到的位置了,也就是說,無論是級聯情況,還是一主多從情況,都可以通過GTID自動找點兒,而無需像之前那樣通過File_name和File_position找點兒了,
簡而言之,GTID的作業流程為:
- master更新資料時,會在事務前產生GTID,一同記錄到binlog日志中,
- slave端的i/o 執行緒將變更的binlog,寫入到本地的relay log中,
- sql執行緒從relay log中獲取GTID,然后對比slave端的binlog是否有記錄,
- 如果有記錄,說明該GTID的事務已經執行,slave會忽略,
- 如果沒有記錄,slave就會從relay log中執行該GTID的事務,并記錄到binlog,
- 在決議程序中會判斷是否有主鍵,如果沒有就用二級索引,如果沒有就用全部掃描,
3.3 GTID主從配置
環境說明:
| 資料庫角色 | IP | 應用與系統版本 |
|---|---|---|
| 主資料庫 | 192.168.111.135 | centos8/redhat8 mysql-5.7 |
| 從資料庫 | 192.168.111.137 | centos8/redhat8 mysql-5.7 |
3.3.1 主庫配置,并重啟mysql
//主庫
[root@localhost ~]# hostnamectl set-hostname master
[root@localhost ~]# bash
[root@master ~]#
//從庫
[root@localhost ~]# hostnamectl set-hostname slave
[root@localhost ~]# bash
[root@slave ~]#
//修改組態檔
[root@master ~]# vim /etc/my.cnf
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-bin=mysql_bin //添加
server-id=10 //添加
gtid_mode=on //添加
enforce-gtid-consistency=true //添加
log-slave-updates=on //添加
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
//重啟mysql服務
[root@master ~]# systemctl restart mysqld
[root@master ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 [::]:22 [::]:*
3.3.2 從庫配置,并重啟mysql
//修改組態檔
[root@slave ~]# vim /etc/my.cnf
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
server-id=20 //添加
relay-log=myrelay //添加
gtid_mode=on //添加
enforce-gtid-consistency=true //添加
log-slave-updates=on //添加
read_only=on //添加
master-info-repository=TABLE //添加
relay-log-info-repository=TABLE //添加
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
//重啟mysql服務
[root@slave ~]# systemctl restart mysqld
[root@slave ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 [::]:22 [::]:*
3.3.3 主庫授權復制用戶
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
mysql> grant replication slave on *.* to 'repl'@'%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)
3.3.4 從庫設定要同步的主庫資訊,并開啟同步
mysql> change master to master_host='192.168.111.135',
-> master_port=3306,master_user='repl',master_password='123456',
-> master_auto_position=1;
Query OK, 0 rows affected, 2 warnings (0.02 sec)
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
mysql> show slave status \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.111.135
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql_bin.000001
Read_Master_Log_Pos: 437
Relay_Log_File: myrelay.000002
Relay_Log_Pos: 650
Relay_Master_Log_File: mysql_bin.000001
Slave_IO_Running: Yes //此行為yes
Slave_SQL_Running: Yes //此行為yes
Replicate_Do_DB:
Replicate_Ignore_DB:
3.3.5 測驗驗證
//查看主庫
[root@master ~]# mysql -uroot -p123456 -e'show databases;'
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
//查看從庫
[root@slave ~]# mysql -uroot -p123456 -e'show databases;'
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
//主庫創建資料庫和表
mysql> create database runtime;
Query OK, 1 row affected (0.00 sec)
mysql> use runtime;
Database changed
mysql> create table zxr (id int not null,name varchar(50) not null,age tinyint);
Query OK, 0 rows affected (0.02 sec)
mysql> insert into zxr values (1,'sean',20),(2,'tom',23),(3,'jerry',30);
Query OK, 3 rows affected (0.02 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql>
mysql>
mysql> select * from zxr;
+----+-------+------+
| id | name | age |
+----+-------+------+
| 1 | sean | 20 |
| 2 | tom | 23 |
| 3 | jerry | 30 |
+----+-------+------+
3 rows in set (0.00 sec)
//從庫查看是否同步
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| runtime |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql> use runtime;
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
mysql> show tables;
+-------------------+
| Tables_in_runtime |
+-------------------+
| zxr |
+-------------------+
1 row in set (0.00 sec)
mysql> select * from zxr;
+----+-------+------+
| id | name | age |
+----+-------+------+
| 1 | sean | 20 |
| 2 | tom | 23 |
| 3 | jerry | 30 |
+----+-------+------+
3 rows in set (0.00 sec)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/500861.html
標籤:MySQL
