新聞中心

成都創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括天柱網(wǎng)站建設(shè)、天柱網(wǎng)站制作、天柱網(wǎng)頁(yè)制作以及天柱網(wǎng)絡(luò)營(yíng)銷策劃等。多年來(lái),我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,天柱網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到天柱省份的部分城市,未來(lái)相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
啟動(dòng) MySQL 服務(wù)后,可以使用以下命令來(lái)登錄。
mysql -h hostname|hostlP -p port -u username -p DatabaseName -e "SQL語(yǔ)句"
對(duì)上述參數(shù)說(shuō)明如下:
- -h:指定連接 MySQL 服務(wù)器的地址??梢杂脙煞N方式表示,hostname 為主機(jī)名,hostIP 為主機(jī) IP 地址。
- -p:指定連接 MySQL 服務(wù)器的端口號(hào),port 為連接的端口號(hào)。MySQL 的默認(rèn)端口號(hào)是 3306,因此如果不指定該參數(shù),默認(rèn)使用 3306 連接 MySQL 服務(wù)器。
- -u:指定連接 MySQL 服務(wù)器的用戶名,username 為用戶名。
- -p:提示輸入密碼,即提示 Enter password。
- DatabaseName:指定連接到 MySQL 服務(wù)器后,登錄到哪一個(gè)數(shù)據(jù)庫(kù)中。如果沒有指定,默認(rèn)為 mysql 數(shù)據(jù)庫(kù)。
- -e:指定需要執(zhí)行的 SQL 語(yǔ)句,登錄 MySQL 服務(wù)器后執(zhí)行這個(gè) SQL 語(yǔ)句,然后退出 MySQL 服務(wù)器。
例 1
下面使用 root 用戶登錄到 test 數(shù)據(jù)庫(kù)中,命令和運(yùn)行過(guò)程如下:
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.
上述命令中,通過(guò)值 localhost 指定 MySQL 服務(wù)器的地址,參數(shù) -u 指定了登錄 MySQL 服務(wù)器的用戶賬戶,參數(shù) -p 表示會(huì)出現(xiàn)輸入密碼提示信息,最后值“test”指定了登錄成功后要使用的數(shù)據(jù)庫(kù)。
由結(jié)果可以看到,輸入命令后,會(huì)出現(xiàn)“Enter password”提示信息,在這條信息之后輸入密碼,然后按 Enter 鍵。密碼正確后,就成功登錄到 MySQL 服務(wù)器了。
例 2
下面使用 root 用戶登錄到自己計(jì)算機(jī)的 mysql 數(shù)據(jù)庫(kù),同時(shí)查詢 student 表的表結(jié)構(gòu),命令和運(yùn)行過(guò)程如下:
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í)行命令并輸入正確密碼后,窗口中就會(huì)顯示出 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í)行后,后面不會(huì)提示輸入密碼。因?yàn)?-p 后面有密碼,MySQL 會(huì)直接使用這個(gè)密碼。
退出 MySQL 服務(wù)器的方式很簡(jiǎn)單,只要在命令行輸入 EXIT 或 QUIT 即可。“\q”是 QUIT 的縮寫,也可以用來(lái)退出 MySQL 服務(wù)器。退出后就會(huì)顯示 Bye。如下所示:
mysql> QUIT; Bye
當(dāng)前文章:MySQL登錄和退出服務(wù)器
網(wǎng)站網(wǎng)址:http://www.dlmjj.cn/article/djcjgcs.html


咨詢
建站咨詢
