日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)數(shù)據(jù)庫教程:MySQL登錄和退出服務(wù)器

在《 登錄MySQL數(shù)據(jù)庫》一節(jié),我們了解到用戶可以通過 mysql 命令來登錄 MySQL 服務(wù)器。但是前面還有些參數(shù)沒有介紹到,本節(jié)將詳細(xì)介紹 MySQL 中登錄和退出服務(wù)器的方法。

啟動 MySQL 服務(wù)后,可以使用以下命令來登錄。

mysql -h hostname|hostlP -p port -u username -p DatabaseName -e "SQL語句"

對上述參數(shù)說明如下:

  • -h:指定連接 MySQL 服務(wù)器的地址。可以用兩種方式表示,hostname 為主機(jī)名,hostIP 為主機(jī) IP 地址。
  • -p:指定連接 MySQL 服務(wù)器的端口號,port 為連接的端口號。MySQL 的默認(rèn)端口號是 3306,因此如果不指定該參數(shù),默認(rèn)使用 3306 連接 MySQL 服務(wù)器。
  • -u:指定連接 MySQL 服務(wù)器的用戶名,username 為用戶名。
  • -p:提示輸入密碼,即提示 Enter password。
  • DatabaseName:指定連接到 MySQL 服務(wù)器后,登錄到哪一個數(shù)據(jù)庫中。如果沒有指定,默認(rèn)為 mysql 數(shù)據(jù)庫。
  • -e:指定需要執(zhí)行的 SQL 語句,登錄 MySQL 服務(wù)器后執(zhí)行這個 SQL 語句,然后退出 MySQL 服務(wù)器。

例 1

下面使用 root 用戶登錄到 test 數(shù)據(jù)庫中,命令和運(yùn)行過程如下:

C:\Users\11645>mysql -h localhost -u root -p test
Enter password: ****
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.29-log MySQL Community Server (GPL)

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.

上述命令中,通過值 localhost 指定 MySQL 服務(wù)器的地址,參數(shù) -u 指定了登錄 MySQL 服務(wù)器的用戶賬戶,參數(shù) -p 表示會出現(xiàn)輸入密碼提示信息,最后值“test”指定了登錄成功后要使用的數(shù)據(jù)庫。

由結(jié)果可以看到,輸入命令后,會出現(xiàn)“Enter password”提示信息,在這條信息之后輸入密碼,然后按 Enter 鍵。密碼正確后,就成功登錄到 MySQL 服務(wù)器了。

例 2

下面使用 root 用戶登錄到自己計(jì)算機(jī)的 mysql 數(shù)據(jù)庫,同時查詢 student 表的表結(jié)構(gòu),命令和運(yùn)行過程如下:

C:\Users\11645>mysql -h localhost -u root -p test -e"DESC student"
Enter password: ****
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(4)      | NO   | PRI | NULL    |       |
| name  | varchar(20) | YES  |     | NULL    |       |
| age   | int(4)      | YES  |     | NULL    |       |
| stuno | int(11)     | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+

結(jié)果顯示,執(zhí)行命令并輸入正確密碼后,窗口中就會顯示出 student 表的基本結(jié)構(gòu)。

用戶也可以直接在 mysql 命令的 -p 后加上登錄密碼,登錄密碼與 -p 之間沒有空格。

例 3

下面使用 root 用戶登錄到自己計(jì)算機(jī)的 MySQL 服務(wù)器中,密碼直接加在 mysql 命令中。命令如下:

C:\Users\11645>mysql -h localhost -u root -proot
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 4
Server version: 5.7.29-log MySQL Community Server (GPL)

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.

上述命令執(zhí)行后,后面不會提示輸入密碼。因?yàn)?-p 后面有密碼,MySQL 會直接使用這個密碼。

退出 MySQL 服務(wù)器的方式很簡單,只要在命令行輸入 EXIT 或 QUIT 即可。“\q”是 QUIT 的縮寫,也可以用來退出 MySQL 服務(wù)器。退出后就會顯示 Bye。如下所示:

mysql> QUIT;
Bye

當(dāng)前標(biāo)題:創(chuàng)新互聯(lián)數(shù)據(jù)庫教程:MySQL登錄和退出服務(wù)器
文章分享:http://m.5511xx.com/article/djjdcdc.html