1. 程式人生 > 其它 >mysql客戶端操作技巧

mysql客戶端操作技巧

轉自:https://mp.weixin.qq.com/s/dM_Kr23h-yXo61uSf8uPNQ

引言

作為一個MySQL資料庫從業者,我們最常用的工具就是mysql了,然而如何讓它變的更好用,你瞭解嗎?

mysql Client Commands

作為連線MySQL資料庫的工具,mysql其實有很多非常有用的命令設定,有一些是我們日常使用的,比如\g、\G、\q,也有我們不太常用的\P、\T。今天分享一下我對這些設定的理解,希望能對大家在日常的工作中,有所幫助。

 

 

支援哪些設定

mysql提供了help命令,用以說明支援哪些命令的設定,我們先看一下

GreatDB Cluster[(none)]> help ;

For information about Percona products and services, visit:
   http://www.percona.com/
Percona Server manual: http://www.percona.com/doc/percona-server/8.0/
For the MySQL Reference Manual: http://dev.mysql.com/
To buy Percona support, training, or other products, visit:
   https://www.percona.com/

List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
?         (\?) Synonym for 'help'.
clear     (\c) Clear the current input statement.
connect   (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit      (\e) Edit command with $EDITOR.
ego       (\G) Send command to mysql server, display result vertically.
exit      (\q) Exit mysql. Same as quit.
go        (\g) Send command to mysql server.
help      (\h) Display this help.
nopager   (\n) Disable pager, print to stdout.
notee     (\t) Don't write into outfile.
pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print     (\p) Print current command.
prompt    (\R) Change your mysql prompt.
quit      (\q) Quit mysql.
rehash    (\#) Rebuild completion hash.
source    (\.) Execute an SQL script file. Takes a file name as an argument.
source_decrypt Execute an encrypted script file. Takes file name, decrypt key as arguments.
status    (\s) Get status information from the server.
system    (\!) Execute a system shell command.
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
use       (\u) Use another database. Takes database name as argument.
charset   (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings  (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
resetconnection(\x) Clean session context.
query_attributes Sets string parameters (name1 value1 name2 value2 ...) for the next query to pick up.

For server side help, type 'help contents'

?

顯示幫助資訊,列出所有支援的操作命令,這個最簡單,就不做進一步說明了。

clear(\c)

MySQL手冊介紹為清除當前輸入的SQL語句,我個人更願意理解為撤銷已輸入SQL的執行。看下面的例子:

GreatDB Cluster[test]> select * from tt1;
+------+------+------+------+
| id   | dd   | c1   | c2   |
+------+------+------+------+
|    1 | aaa  | NULL | NULL |
|    2 | bbb  | NULL | NULL |
|    3 | NULL | NULL | NULL |
|    4 | 8    | NULL | NULL |
|    5 | NULL | NULL | NULL |
+------+------+------+------+
5 rows in set (0.01 sec)

GreatDB Cluster[test]> delete from tt1 
    -> where id = 5 
    -> and c1 is not null
    -> 

當我輸入完上面的SQL時,發現邏輯未考慮全,不想執行這個SQL了,怎麼辦呢?這裡有好幾種解決辦法:你可以ctrl+c 終止命令的執行,也可以關閉當前的mysql客戶端,甚至關閉操作命令的電腦。然後有一種標準且簡單的方式,就是在命令的最後加上\c,就可以實現:

GreatDB Cluster[test]> delete from tt1 
    -> where id = 5 
    -> and c1 is not null
    -> \c
GreatDB Cluster[test]>

可以看到,在命令視窗最後輸入\c後,SQL不會被執行,並且重新啟動新的命令列接收客戶端輸入。需要注意的是:\c

和需要取消的SQL間,不能有分隔符(預設為分號;),否則會先執行分隔符前面的SQL,然後再執行\c,這時就達不到取消已輸入SQL執行的效果了。

connect(\r)

重新連線資料庫服務端,支援重連過程中,指定database名字和連線主機。

這個功能看起來好像沒什麼新奇的,客戶端執行了SQL,就算連線超時了,預設情況下,自動就會重新連線服務端。

但是在MGR、主從複製場景下,如果所有例項的維護賬號都具有相同的使用者名稱、密碼、埠,那麼通過\r就很方便的切換多個例項進行維護,而不需要重新輸入其他連線資訊

GreatDB Cluster[test]> select @@report_host;
+---------------+
| @@report_host |
+---------------+
| 172.16.50.82  |
+---------------+
1 row in set (0.00 sec)

GreatDB Cluster[test]> \r test 172.16.50.81
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Connection id:    911698
Current database: test

GreatDB Cluster[test]> select @@report_host;
+---------------+
| @@report_host |
+---------------+
| 172.16.50.81  |
+---------------+
1 row in set (0.00 sec)

GreatDB Cluster[test]> 

重連資訊中的ip地址,也可以是在/etc/hosts中配置的主機名

GreatDB Cluster[test]> select @@report_host;
+---------------+
| @@report_host |
+---------------+
| 172.16.50.81  |
+---------------+
1 row in set (0.00 sec)

GreatDB Cluster[test]> \r test greatdb82
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Connection id:    2460607
Current database: test

GreatDB Cluster[test]> select @@report_host;
+---------------+
| @@report_host |
+---------------+
| 172.16.50.82  |
+---------------+
1 row in set (0.00 sec)

GreatDB Cluster[test]>

delimiter(\d)

自定義分隔符,在建立、修改儲存過程、函式、觸發器、事件、檢視都會用到,替換用於替換預設的分號分隔符。

edit(\e)

官網解釋說命令用於編輯當前輸入SQL命令,預設的編輯器是vi,也可以通過設定環境變數EDITOR來改變成其他的編輯器,比如調整為vim編輯器export EDITOR=$(which vim)

有這個命令後,輸出錯誤的SQL,就不需要再用\c終止了,而是直接在其後加上\e進行編輯,修改成正確的後,再執行。

比如我實際上想要執行的命令中tt2表不存在,那麼只需要通過\e更新SQL語句中的表名字就可以繼續執行,不需要再重新編輯整條SQL。

GreatDB Cluster[test]> select * from test.tt2 \e

vi中替換表名字的操作就不再演示了,編輯後的執行情況如下:

GreatDB Cluster[test]> select * from test.tt2 \e 
    -> ;
+------+------+------+------+
| id   | dd   | c1   | c2   |
+------+------+------+------+
|    1 | aaa  | NULL | NULL |
|    2 | bbb  | NULL | NULL |
|    3 | NULL | NULL | NULL |
|    4 | 8    | NULL | NULL |
|    5 | NULL | NULL | NULL |
+------+------+------+------+
5 rows in set (0.01 sec)

GreatDB Cluster[test]>

另外在測試過程中,還發現\e可以對上一次執行的SQL進行編輯,即單獨執行\e時,其實是對上次執行的SQL命令做編輯。

GreatDB Cluster[test]> \e
select * from test.tt1

這裡有人就會想到,我按向上的方向鍵,也能編輯上一條SQL呀,何必這麼麻煩,這裡有下面的SQL情況,有多次換行,或者結構更復雜的SQL

GreatDB Cluster[test]> select * from test.z1
    -> join test.z2 
    -> using(id)
    -> limit 3;
+------+------+------+
| id   | name | name |
+------+------+------+
|    1 | 11   | 11   |
|    2 | 22   | 22   |
|   11 | 11   | 11   |
+------+------+------+
3 rows in set (0.00 sec)

GreatDB Cluster[test]>

如果按上的方向鍵,整個SQL語句結構就發生了變化,本來規整的SQL語句,變成了很長的一行,很難調整,但是使用\e就不會有這種情況,會保持之前的輸入結構,更方便語句的調整

GreatDB Cluster[test]> select * from test.z1
    -> join test.z2 
    -> using(id)
    -> limit 3;
+------+------+------+
| id   | name | name |
+------+------+------+
|    1 | 11   | 11   |
|    2 | 22   | 22   |
|   11 | 11   | 11   |
+------+------+------+
3 rows in set (0.00 sec)

GreatDB Cluster[test]> \e

select * from test.z1
join test.z2
using(id)
limit 3

另外,有同學經常苦惱,我昨天才輸入的SQL命令,如果需要重新執行,又得輸入一遍,其實這裡也有一個小技巧,通過快捷鍵CTRL+R,輸入SQL中的關鍵資訊(比如表名字),就能快速翻出對應的SQL,如果匹配出來的行不是想要的SQL,可以繼續按CTRL+R繼續上翻,直到查詢到需要的SQL,當然,也有可能需要的SQL已經被清理出歷史記錄中,這種情況是無法被找到的。

ego(\G)

提交SQL語句到伺服器,並且將返回的資料列式顯示。

exit(\q)

退出mysql客戶端連線。

go(\g)

提交SQL語句到伺服器。

pager(\P)

設定pager規則,對查詢結果執行pager規則後,再輸出結果。這也是一個非常有用的設定,我們常常因為processlist結果太多而不方便檢視,需要通過單行grep或者查詢information_schema.processlist來實現,有這個工具後,我們看看效果

GreatDB Cluster[test]> show processlist;
+---------+-----------------+--------------------+------+---------+---------+--------------------------------------------------------+----------------------------------+------------+-----------+---------------+
| Id      | User            | Host               | db   | Command | Time    | State                                                  | Info                             | Time_ms    | Rows_sent | Rows_examined |
+---------+-----------------+--------------------+------+---------+---------+--------------------------------------------------------+----------------------------------+------------+-----------+---------------+
|       6 | event_scheduler | localhost          | NULL | Daemon  | 5019248 | Waiting on empty queue                                 | NULL                             | 5019247326 |         0 |             0 |
|      26 | system user     |                    | NULL | Connect | 5018577 | waiting for handler commit                             | Group replication applier module | 5018576436 |         0 |             0 |
|      29 | system user     |                    | NULL | Query   |    1010 | Slave has read all relay log; waiting for more updates | NULL                             |    1010045 |         0 |             0 |
|      30 | system user     |                    | NULL | Query   |    1010 | Waiting for an event from Coordinator                  | NULL                             |    1010045 |         0 |             0 |
|      31 | system user     |                    | NULL | Query   |  100958 | Waiting for an event from Coordinator                  | NULL                             |  100956966 |         0 |             0 |
|      32 | system user     |                    | NULL | Query   |  100958 | Waiting for an event from Coordinator                  | NULL                             |  100956966 |         0 |             0 |
|      33 | system user     |                    | NULL | Connect | 5018577 | Waiting for an event from Coordinator                  | NULL                             | 5018576419 |         0 |             0 |
|      34 | system user     |                    | NULL | Connect | 5018577 | Waiting for an event from Coordinator                  | NULL                             | 5018576418 |         0 |             0 |
|      35 | system user     |                    | NULL | Connect | 5018577 | Waiting for an event from Coordinator                  | NULL                             | 5018576417 |         0 |             0 |
|      36 | system user     |                    | NULL | Connect | 5018577 | Waiting for an event from Coordinator                  | NULL                             | 5018576415 |         0 |             0 |
|      37 | system user     |                    | NULL | Connect | 5018577 | Waiting for an event from Coordinator                  | NULL                             | 5018576413 |         0 |             0 |
|   31568 | greatdb.sys     | localhost          | NULL | Sleep   | 4861529 | NULL                                                   | PLUGIN                           | 4861528879 |         0 |             0 |
| 2460607 | greatdb         | 172.16.50.81:59062 | test | Query   |       0 | init                                                   | show processlist                 |          0 |         0 |             0 |
| 2466518 | greatdb.sys     | localhost          | NULL | Sleep   |       1 | NULL                                                   | PLUGIN                           |        947 |         0 |             1 |
+---------+-----------------+--------------------+------+---------+---------+--------------------------------------------------------+----------------------------------+------------+-----------+---------------+
14 rows in set (0.00 sec)

GreatDB Cluster[test]> \P grep -vE 'system user|Sleep'
PAGER set to 'grep -vE 'system user|Sleep''
GreatDB Cluster[test]> show processlist;
+---------+-----------------+--------------------+------+---------+---------+--------------------------------------------------------+----------------------------------+------------+-----------+---------------+
| Id      | User            | Host               | db   | Command | Time    | State                                                  | Info                             | Time_ms    | Rows_sent | Rows_examined |
+---------+-----------------+--------------------+------+---------+---------+--------------------------------------------------------+----------------------------------+------------+-----------+---------------+
|       6 | event_scheduler | localhost          | NULL | Daemon  | 5019255 | Waiting on empty queue                                 | NULL                             | 5019255045 |         0 |             0 |
| 2460607 | greatdb         | 172.16.50.81:59062 | test | Query   |       0 | init                                                   | show processlist                 |          0 |         0 |             0 |
+---------+-----------------+--------------------+------+---------+---------+--------------------------------------------------------+----------------------------------+------------+-----------+---------------+
14 rows in set (0.01 sec)

GreatDB Cluster[test]>

pager後面可以跟很多的shell命令,比如awk、grep、wc ,對結果集的處理,當SQL不方便處理而shell方便處理時,不用再使用-e引數每次都進行連線,然後處理,比如主從結構對Slave_IO_Running、Slave_SQL_Running的監控,可設定pager grep -E 'Slave_IO_Running|Slave_SQL_Running'

pager的另外一個用途:經常有同學問,一些欄位中是否有包含某些特定字串,正常的SQL處理是需要寫成col1 like '%abc%' or col2 like '%abc%'...,寫出來後SQL結構相對複雜,通過pager設定pager grep -i abc; select * from tab即可方便檢視。

nopager(\n)

pager的設定是整個session生命週期內都生效,通過執行nopager進行關閉設定

prompt(\R)

修改mysql客戶端的命令列提示資訊,支援顯示的提示資訊非常多,具體可以參見MySQL官網介紹。修改mysql客戶端的命令列提示資訊,也有好幾種方式:

1、設定作業系統環境變數MYSQL_PS1 export MYSQL_PS1= " \D_\h_\p_\u > ",格式為"時間_主機_埠_使用者名稱"

2、通過客戶端的命令prompt修改 \R \D_\h_\p_\u >

3、通過my.cnf的[mysql]域進行配置

[mysql]
prompt="\R \D_\h_\p_\u > "

4、如果session中通過\R xxx 臨時修改了命令列提示資訊,可以通過單獨執行\R來恢復預設設定。

quit(\q)

退出當前session連線。

auto-rehash(#)

在使用mysql客戶端連線伺服器時,預設情況下會自動收集一些元資料資訊,在後續輸入SQL命令時可以通過tab鍵補齊命令,比如補齊表名字、列名字。

GreatDB Cluster[test]> select * from tt(此時按tab鍵)
tt1     tt1.c1  tt1.c2  tt1.dd  tt1.id  ttt     ttt.id

但是如果在session中新建了表,或者給表上新增了欄位,是無法通過tab鍵補齊的,這時通過\#命令重新整理元資料資訊,之後就能對新的DDL結構進行補齊

GreatDB Cluster[test]> create table tt2 as select * from tt1;
Query OK, 5 rows affected (0.09 sec)
Records: 5  Duplicates: 0  Warnings: 0

GreatDB Cluster[test]> select * from tt(此時按tab鍵)
tt1     tt1.c1  tt1.c2  tt1.dd  tt1.id  ttt     ttt.id  
GreatDB Cluster[test]> \#
GreatDB Cluster[test]> select * from tt(此時按tab鍵)
tt1     tt1.c1  tt1.c2  tt1.dd  tt1.id  tt2     tt2.c1  tt2.c2  tt2.dd  tt2.id  ttt     ttt.id  
GreatDB Cluster[test]> select * from tt

source(\.)

命令後需要跟一個檔名,\. filename會對filename檔案中的內容按標準SQL進行解析執行。

status(\s)

輸出本次連線的相關資訊及伺服器的一些資訊,如果連線時指定了--safe-updates,還會輸出查詢限制相關的資訊,\s輸出了很多有用的資訊,可仔細閱讀。

[#8#root@greatdb81 ~ 20:26:13]8 m5 3306 --safe-updates 
greatsql: [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 916197
Server version: 8.0.25-15-greatdbcluster5.1.8-RC-6 GreatDB Cluster, Release RC-6, Revision 60ab7f36025

Copyright (c) 2009-2021 BEIJING GREAT OPENSOURCE SOFTWARE TECHNOLOGY CO.,LTD. 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

GreatDB Cluster[(none)]> \s
--------------
/greatdb/svr/greatdb/bin/greatsql  Ver 8.0.25-15-greatdbcluster5.1.8-RC-6 for Linux on x86_64 (GreatDB Cluster, Release RC-6, Revision 60ab7f36025)

Connection id:  916197
Current database: 
Current user:  [email protected]
SSL:   Cipher in use is ECDHE-RSA-AES128-GCM-SHA256
Current pager:  stdout
Using outfile:  ''
Using delimiter: ;
Server version:  8.0.25-15-greatdbcluster5.1.8-RC-6 GreatDB Cluster, Release RC-6, Revision 60ab7f36025
Protocol version: 10
Connection:  127.0.0.1 via TCP/IP
Server characterset: utf8mb4
Db     characterset: utf8mb4
Client characterset: utf8mb4
Conn.  characterset: utf8mb4
TCP port:  3306
Binary data as:  Hexadecimal
Uptime:   51 days 9 hours 5 min 13 sec

Threads: 16  Questions: 4354604  Slow queries: 339  Opens: 19188  Flush tables: 3  Open tables: 6095  Queries per second avg: 0.980

Note that you are running in safe_update_mode:
UPDATEs and DELETEs that don't use a key in the WHERE clause are not allowed.
(One can force an UPDATE/DELETE by adding LIMIT # at the end of the command.)
SELECT has an automatic 'LIMIT 1000' if LIMIT is not used.
Max number of examined row combination in a join is set to: 1000000

--------------

GreatDB Cluster[(none)]>

system(!)

使用預設命令直譯器執行給定命令,簡單的說就是返回到作業系統執行\!之後的命令,比如下面

GreatDB Cluster[(none)]> \! date
2022年 11月 16日 星期三 20:32:34 CST
GreatDB Cluster[(none)]> \! pwd
/root
GreatDB Cluster[(none)]> \! cd /greatdb
GreatDB Cluster[(none)]> \! vmstat -w
procs -----------------------memory---------------------- ---swap-- -----io---- -system-- --------cpu--------
 r  b         swpd         free         buff        cache   si   so    bi    bo   in   cs  us  sy  id  wa  st
 1  0            0       358508            0      3117236    0    0   486    20    0    0   5   3  92   0   0
GreatDB Cluster[(none)]>

在8.0.19之前,只支援在unix系統中使用該命令,到8.0.19後,在windows中也支援了該命令。

tee(\T)

將所有執行的SQL命令及輸出結果儲存到指定檔案中。這在調測、生產維護過程中,都是非常有用的一個功能,特別是一些安全要求高的環境中,控制檯只能顯示幾十行命令時,想要查詢之前執行的命令及執行的結果比較難,此時就能用上\T了。

GreatDB Cluster[(none)]> \T /root/a.log
Logging to file '/root/a.log'
GreatDB Cluster[(none)]> select * from test.tt1;
+------+------+------+------+
| id   | dd   | c1   | c2   |
+------+------+------+------+
|    1 | aaa  | NULL | NULL |
|    2 | bbb  | NULL | NULL |
|    3 | NULL | NULL | NULL |
|    4 | 8    | NULL | NULL |
|    5 | NULL | NULL | NULL |
+------+------+------+------+
5 rows in set (0.01 sec)

GreatDB Cluster[(none)]> \! cat /root/a.log
GreatDB Cluster[(none)]> select * from test.tt1;
+------+------+------+------+
| id   | dd   | c1   | c2   |
+------+------+------+------+
|    1 | aaa  | NULL | NULL |
|    2 | bbb  | NULL | NULL |
|    3 | NULL | NULL | NULL |
|    4 | 8    | NULL | NULL |
|    5 | NULL | NULL | NULL |
+------+------+------+------+
5 rows in set (0.01 sec)

GreatDB Cluster[(none)]> 

如果想要記錄每個人登入資料庫,做了哪些操作,由於tee不支援根據當前時間動態產生日誌檔名,我們可以這樣設定

## 首先建立一個log目錄
mkdir -p /greatdb/logs/client/

## 然後設定環境變數,為了連線安全,建議使用--login-path的方式進行登入,我這裡使用的是gdb1登入。

echo "alias mlogin='mysql --login-path=gdb1 --tee /greatdb/logs/client/\$(date +%Y-%m-%d_%H-%M-%S).log'" >> ~/.bashrc; source ~/.bashrc

[#15#root@greatdb81 /greatdb/logs/client 20:48:53]15 echo "alias mlogin='mysql --login-path=gdb1 --tee /greatdb/logs/client/$(date +\"%Y-%m-%d_%H-%M\").log'" >> ~/.bashrc; source ~/.bashrc

## 通過設定的alias登入資料庫

[#16#root@greatdb81 /greatdb/logs/client 20:49:43]16 mlogin 
Logging to file '/greatdb/logs/client/2022-11-16_20-49.log'
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 916482
Server version: 8.0.25-15-greatdbcluster5.1.8-RC-6 GreatDB Cluster, Release RC-6, Revision 60ab7f36025

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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> show tables from tpcc;
+------------------+
| Tables_in_tpcc   |
+------------------+
| bmsql_config     |
| bmsql_customer   |
| bmsql_district   |
| bmsql_history    |
| bmsql_item       |
| bmsql_new_order  |
| bmsql_oorder     |
| bmsql_order_line |
| bmsql_stock      |
| bmsql_warehouse  |
| datatypes1       |
| datatypes10      |
| datatypes11      |
| datatypes2       |
| datatypes3       |
| datatypes4       |
| datatypes5       |
| datatypes6       |
| datatypes7       |
| datatypes8       |
| datatypes9       |
+------------------+
21 rows in set (0.00 sec)

mysql>

我們發現指定的日誌目錄中,已經有了日誌檔案,並且記錄了所有執行的SQL及輸出結果

[#9#root@greatdb81 ~ 20:51:43]9 cd /greatdb/logs/client/
[#10#root@greatdb81 /greatdb/logs/client 20:51:48]10 ll
總用量 8
-rw-r--r-- 1 root root  627 11月 16 20:48 2022-11-16_20-48.log
-rw-r--r-- 1 root root 3214 11月 16 20:50 2022-11-16_20-49.log
[#11#root@greatdb81 /greatdb/logs/client 20:51:48]11

notee(\t)

取消\T設定,不再記錄操作資訊到日誌檔案中。

use(\u)

切換當前連線的database。

warnings(\W)

在執行完SQL語句後,立即顯示warning資訊,不需要再手動執行show warnings;了。

nowarnings(\w)

在執行完SQL語句後,不立即顯示warning資訊,需要手動執行show warnings;才會顯示warning資訊。

resetconnection(\x)

以新連線的狀態重新連線到伺服器,並且進行一些資訊的清理及復位,不需要再次進行許可權驗證。主要影響如下資訊:

  1. 回滾所有活動的事務,並重置自動提交模式。
  2. 所有DML鎖均已釋放。
  3. 所有TEMPORARY table 均已關閉(並刪除)。
  4. 會話系統變數將重新初始化。
  5. 使用者變數設定丟失。
  6. 準備好的語句被釋放。
  7. HANDLER關閉。
  8. LAST_INSERT_ID 置為 0。
  9. 用 GET_LOCK 釋放。

可以參考8.0.26的程式碼libmysql.cc中4429~4444行

int STDCALL mysql_reset_connection(MYSQL *mysql) {
  DBUG_TRACE;
  if (simple_command(mysql, COM_RESET_CONNECTION, nullptr, 0, 0))
    return 1;
  else {
    mysql_detach_stmt_list(&mysql->stmts, "mysql_reset_connection");
    /* reset some of the members in mysql */
    mysql->insert_id = 0;
    mysql->affected_rows = ~(uint64_t)0;
    free_old_query(mysql);
    mysql->status = MYSQL_STATUS_READY;
    mysql_extension_bind_free(MYSQL_EXTENSION_PTR(mysql));
    return 0;
  }
}

query_attributes

通過query_attributes var1 value1 var2 value2來設定變數,然後通過mysql_query_attribute_string('var1')返回變數值value1,目前來看,並沒有發現特殊的使用方法,畢竟我們也可以通過set @var1='value1'來設定。

使用體驗

mysql Client Commands在某些場景下,可以極大的提高我們的操作效率,相對於完整的命令ego、pager、edit等,我更喜歡使用他們的簡寫命令\G、\P、\e,因為有時候完整命令不確定如何正確使用,會導致不生效,但是簡寫命令,是一定會生效的。