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

歡迎訪問 生活随笔!

生活随笔

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

数据库

mysql专业连接工具_mysql(MySQL客户端连接工具)

發布時間:2023/12/10 数据库 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql专业连接工具_mysql(MySQL客户端连接工具) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在MySQL提供的工具中,DBA使用最頻繁的莫過于mysql。這里的mysql不是指MySQL服務,也不是mysql數據庫,而是連接數據庫的客戶端工具。類似于Oracle的sqlplus。

語法:

mysql [options][database]

options是mysql的可用選項,一次可以寫一個或者多個,甚至可以不寫。database表示連接的數據庫,一次只能寫一個或者不寫,如果不寫,在登錄數據庫后還需要使用use dbname選擇數據庫。

mysql的選項通常有兩種表達方式:

-+選項單詞的縮寫+選項值**;

--+選項的完整單詞+=+選項的實際值;

例如:

mysql -uroot -ppassword

mysql --user=root --password=password

1.連接選項

-u,--user=name 指定連接的用戶名

-p,--password=password 指定連接密碼

-h,--host=name 指定服務器IP或域名

-P,--port=3308 指定連接端口

在默認情況下,如果這些選項都不寫,mysql將會使用'用戶'@'localhost'和空密碼連接本機的3306端口。空用戶會在mysql安裝完畢后自動生成,這也就是僅使用mysql命令就能連到數據庫的原因。

如果客戶端和服務器在用一臺機器上,通常不需要指定-h選項,否則需要指定mysql服務所在的IP或主機名。如果不指定端口,默認連接到3306端口。示例如下:

# mysql -h 10.10.200.202 -uroot -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 75520

Server version: 5.6.28 Source distribution

Copyright (c) 2000, 2013, 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>

2.指定客戶端字符集

--default-character-set=charset-name為服務器的字符集選項。該選項可以配置在my.cnf的[mysqld]組中,同樣也可以作為客戶端字符集選項,也可以配置在[mysql]組中。在使用mysql命令登錄數據庫時,使用--default-character-set選項可以指定客戶端的字符集。例如,如果未使用--default-character-set選項登錄數據庫時:

# mysql -h 10.10.200.202 -uroot -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 75520

Server version: 5.6.28 Source distribution

Copyright (c) 2000, 2013, 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 variables like 'chara%';

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

| Variable_name | Value |

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

| character_set_client | latin1 |

| character_set_connection | latin1 |

| character_set_database | utf8 |

| character_set_filesystem | binary |

| character_set_results | latin1 |

| character_set_server | utf8 |

| character_set_system | utf8 |

| character_sets_dir | /usr/local/mysql-5.6.28/share/charsets/ |

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

當使用--default-character-set選項登錄數據庫時:

# mysql -h 10.10.200.202 -uroot -p --default-character-set=utf8

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 75542

Server version: 5.6.28 Source distribution

Copyright (c) 2000, 2013, 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 variables like 'chara%';

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

| Variable_name | Value |

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

| character_set_client | utf8 |

| character_set_connection | utf8 |

| character_set_database | utf8 |

| character_set_filesystem | binary |

| character_set_results | utf8 |

| character_set_server | utf8 |

| character_set_system | utf8 |

| character_sets_dir | /usr/local/mysql-5.6.28/share/charsets/ |

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

8 rows in set (0.01 sec)

3.執行選項

-e,--execute=name?執行sql語句并退出

此選項可以直接在客戶端執行SQL語句,而不用連接到MySQL數據庫后再執行,對于一些腳本的執行,使用此法較為便利。可以使用此種方法連續執行多條SQL語句,語句之間用分號(;)分隔例如:

# mysql -uroot -p mysql -e "select host,user from user"

Enter password:

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

| host | user |

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

| 10.10.200.201 | root |

| 10.10.200.201 | zabbix |

| 127.0.0.1 | root |

| ::1 | root |

| localhost | |

| localhost | root |

| localhost | zabbix |

| tcxx-ops-mysql-202 | |

| tcxx-ops-mysql-202 | root |

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

4.格式化選項

-E,--vertical?將輸出按字段順序垂直顯示

-s,--silent?去掉SQL輸出結果中的線條框

# mysql -uroot -p mysql -e "select host,user from user" -E

Enter password:

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

host: 127.0.0.1

user: root

*************************** 2. row ***************************

host: ::1

user: root

*************************** 3. row ***************************

host: localhost

user:

*************************** 4. row ***************************

host: localhost

user: root

*************************** 5. row ***************************

host: test-server

user:

*************************** 6. row ***************************

host: test-server

user: root

總結

以上是生活随笔為你收集整理的mysql专业连接工具_mysql(MySQL客户端连接工具)的全部內容,希望文章能夠幫你解決所遇到的問題。

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