mysql主從

来源:https://www.cnblogs.com/Their-own/archive/2022/08/01/16542053.html
-Advertisement-
Play Games

mysql主從 1.主從原理 1.1 主從介紹 所謂mysql主從就是建立兩個完全一樣的資料庫,其中一個為主要使用的資料庫,另一個為次要的資料庫,一般在企業中,存放比較重要的數據的資料庫伺服器需要配置主從,這樣可以防止因資料庫伺服器宕機導致數據丟失,還能保證業務量太多、數據太多和訪問人數太多時服務的 ...


mysql主從

目錄

1.主從原理

1.1 主從介紹

所謂mysql主從就是建立兩個完全一樣的資料庫,其中一個為主要使用的資料庫,另一個為次要的資料庫,一般在企業中,存放比較重要的數據的資料庫伺服器需要配置主從,這樣可以防止因資料庫伺服器宕機導致數據丟失,還能保證業務量太多、數據太多和訪問人數太多時服務的質量(伺服器響應速度),還能提供故障切換、讀寫分離、和備份等等功能

1.2 主從作用

  • 實時災備,用於故障切換
  • 讀寫分離,提供查詢服務
  • 備份,避免影響業務

1.3 主從形式

img

一主一從

主主複製:當作備份使用,當主伺服器出現故障時,另一個主伺服器會自動頂上。

一主多從:用來實現讀寫分離,當寫操作較少時,讀操作較多時使用,主伺服器用來實現寫操作,從伺服器用來實現讀操作。

多主一從:用來實現讀寫分離,當寫操作較多時,讀操作較少時使用,主伺服器用來實現寫操作,從伺服器用來實現讀操作。5.7開始支持

聯級複製:是指從主場地複製過來的又從該場地再次複製到其他場地,即A場地把數據複製到B場地,B場地又把這些數據或其中部分數據再複製到其他場地。

1.4 主從複製原理

img

主從複製步驟:

  • 主庫將所有的寫操作記錄到binlog日誌中並生成一個log dump線程,將binlog日誌傳給從庫的I/O線程
  • 從庫生成兩個線程,一個I/O線程,一個SQL線程
    • I/O線程去請求主庫的binlog,並將得到的binlog日誌寫到relay log(中繼日誌) 文件中
    • SQL線程,會讀取relay log文件中的日誌,並解析成具體操作,來實現主從的操作一致,達到最終數據一致的目的

2.主從複製配置

主從複製配置步驟:

  1. 確保從資料庫與主資料庫里的數據一樣
  2. 在主資料庫里創建一個同步賬號授權給從資料庫使用
  3. 配置主資料庫(修改配置文件)
  4. 配置從資料庫(修改配置文件)

需求:
搭建兩台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可以極方便的進行複製結構上的故障轉移,新主設置,這就很好地解決了下麵這個圖所展現出來的問題。

img

如圖, 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中的結構

img

  • GTID event 結構

img

  • 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)

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 曾經的“小霸王”游戲機,讓我們許多80年後、90後度過了一個歡樂愉快的童年,雖然如今這類游戲機和卡帶幾乎已經退出游戲市場,但經典永遠留在了我們這一代人心中。今天給大家分享的小霸王FC經典游戲600合集,帶你回顧童年,重溫經典!希望大家喜歡! 詳情:FC紅白機游戲600合集for mac(小霸王游戲) ...
  • 哪裡有專業級的NTFS格式讀寫工具?Tuxera NTFS 2021 mac中文版是一款非常好用的NTFS讀寫工具,可以讓您完整的讀寫相容NTFS格式驅動器,對磁碟進行訪問、編輯、存儲和傳輸文件等操作。同時還包括開源磁碟管理器等簡單的格式和硬碟維修檢查和修複。 詳情:Tuxera NTFS 2021 ...
  • RAR Extractor是一款非常優秀的壓縮解壓工具,可以幫助用戶提取和預覽多種格式的包(超過 40 種格式),支持解壓RAR、ZIP、7Z、TAR、GZIP、GZ、BZIP2、LZIP、ACE、ISO、PAX、PKG、APK、LBR、MSI、JAR、XZ、LZMA、BZ、LZH、CAB、CPIO ...
  • 拉取nacos docker pull nacos/nacos-server 創建文件夾 日誌文件夾 mkdir -p /root/apply/docker/apply/nacos/logs/ 配置文件夾 mkdir -p /root/apply/docker/apply/nacos/init.d/ ...
  • Xmind 2022 for Mac是一款非常便捷的製作思維導圖的軟體,它有非常豐富的模板可以使用,製作思維導圖可以幫助用戶更高效的進行學習,理清相關學習內容的思路和大體框架,用戶可以根據自己的需求進行自主設計,也可以直接添加模板。 詳情:Xmind 2022 for Mac(思維導圖軟體) 軟體介 ...
  • 基礎知識 ssh:secure shell protocol,安全的遠程登錄 作用:是建立在應用層基礎上的安全協議,實現數據傳輸過程中數據的加密,代替telent協議 使用tcp協議,埠號為22 ssh服務具體的軟體實現: openSSH dropbear OpenSSH:ssh協議的開源實現,l ...
  • 1.mysql資料庫備份與恢復 1.1 資料庫常用備份方案 資料庫備份方案: 冷備份:先把資料庫服務停掉,然後拷貝資料庫目錄下的文件進行備份 物理備份 溫備份: 熱備份:資料庫服務正常運行情況,直接對資料庫進行備份 全量備份:全部備份 增量備份:第一次全備,第二次在第一次全備更改的基礎上備份 差異備 ...
  • 一、Mysql的系統架構圖 二、Mysql存儲引擎 Mysql中的數據是通過一定的方式存儲在文件或者記憶體中的,任何方式都有不同的存儲、查找和更新機制,這意味著選擇不同的方式對於數據的存取有效率的差距。 這種不同的存儲方式在 MySQL中被稱作存儲引擎。 存儲引擎是Mysql資料庫系統的底層組件,數據 ...
一周排行
    -Advertisement-
    Play Games
  • Dapr Outbox 是1.12中的功能。 本文只介紹Dapr Outbox 執行流程,Dapr Outbox基本用法請閱讀官方文檔 。本文中appID=order-processor,topic=orders 本文前提知識:熟悉Dapr狀態管理、Dapr發佈訂閱和Outbox 模式。 Outbo ...
  • 引言 在前幾章我們深度講解了單元測試和集成測試的基礎知識,這一章我們來講解一下代碼覆蓋率,代碼覆蓋率是單元測試運行的度量值,覆蓋率通常以百分比表示,用於衡量代碼被測試覆蓋的程度,幫助開發人員評估測試用例的質量和代碼的健壯性。常見的覆蓋率包括語句覆蓋率(Line Coverage)、分支覆蓋率(Bra ...
  • 前言 本文介紹瞭如何使用S7.NET庫實現對西門子PLC DB塊數據的讀寫,記錄了使用電腦模擬,模擬PLC,自至完成測試的詳細流程,並重點介紹了在這個過程中的易錯點,供參考。 用到的軟體: 1.Windows環境下鏈路層網路訪問的行業標準工具(WinPcap_4_1_3.exe)下載鏈接:http ...
  • 從依賴倒置原則(Dependency Inversion Principle, DIP)到控制反轉(Inversion of Control, IoC)再到依賴註入(Dependency Injection, DI)的演進過程,我們可以理解為一種逐步抽象和解耦的設計思想。這種思想在C#等面向對象的編 ...
  • 關於Python中的私有屬性和私有方法 Python對於類的成員沒有嚴格的訪問控制限制,這與其他面相對對象語言有區別。關於私有屬性和私有方法,有如下要點: 1、通常我們約定,兩個下劃線開頭的屬性是私有的(private)。其他為公共的(public); 2、類內部可以訪問私有屬性(方法); 3、類外 ...
  • C++ 訪問說明符 訪問說明符是 C++ 中控制類成員(屬性和方法)可訪問性的關鍵字。它們用於封裝類數據並保護其免受意外修改或濫用。 三種訪問說明符: public:允許從類外部的任何地方訪問成員。 private:僅允許在類內部訪問成員。 protected:允許在類內部及其派生類中訪問成員。 示 ...
  • 寫這個隨筆說一下C++的static_cast和dynamic_cast用在子類與父類的指針轉換時的一些事宜。首先,【static_cast,dynamic_cast】【父類指針,子類指針】,兩兩一組,共有4種組合:用 static_cast 父類轉子類、用 static_cast 子類轉父類、使用 ...
  • /******************************************************************************************************** * * * 設計雙向鏈表的介面 * * * * Copyright (c) 2023-2 ...
  • 相信接觸過spring做開發的小伙伴們一定使用過@ComponentScan註解 @ComponentScan("com.wangm.lifecycle") public class AppConfig { } @ComponentScan指定basePackage,將包下的類按照一定規則註冊成Be ...
  • 操作系統 :CentOS 7.6_x64 opensips版本: 2.4.9 python版本:2.7.5 python作為腳本語言,使用起來很方便,查了下opensips的文檔,支持使用python腳本寫邏輯代碼。今天整理下CentOS7環境下opensips2.4.9的python模塊筆記及使用 ...