MySQL基本命令

2021-06-23 03:20:55 字數 2443 閱讀 2606

mysql常用命令一(登入、增加使用者、密碼更改) 

一、連線mysql  

首先在開啟 dos 視窗,然後進入目錄 %mysqlpath%\bin>,%mysqlpath%是mysql安裝的主目錄,再鍵入命令:mysql -uroot -p,回車後提示你輸密碼,如果剛安裝好 mysql,超級使用者 root 是沒有密碼的,故直接回車即可進入到mysql中了,mysql的提示符是:mysql>. c:\program files\mysql\mysql server 5.0\bin>mysql -u root -p enter password: 

welcome to the mysql monitor.? commands end with  or \g. your mysql connection id is 7 to server version: 5.0.7-beta-nt type 'help;' or '\h' for help. type '\c' to clear the buffer. mysql>  

例2:連線到遠端主機上的 mysql。 

假設遠端主機的ip為:192.168.9.168,使用者名為root,密碼為abcd123。則鍵入以下命令: mysql -h110.110.110.110 -uroot -pabcd123 如圖: 

c:\program files\mysql\mysql server 5.0\bin>mysql -h 192.168.9.168 -u root -p enter password: 

welcome to the mysql monitor.? commands end with  or \g. your mysql connection id is 9 to server version: 5.0.7-beta-nt type 'help;' or '\h' for help. type '\c' to clear the buffer. mysql>  

二、增加新使用者。 

(注意:下面的因為是 mysql 環境中的命令,所以命令後面都帶乙個分號作為結束符) 格式:grant select on 資料庫.* to 使用者名稱@登入主機 identified by "密碼"; 

例1、增加乙個使用者 test1 密碼為 abc123,讓他可以在任何主機上登入,並對所有資料庫有查詢、插入、修改、刪除的許可權。首先用以 root 使用者連入 mysql,然後鍵入以下命令:  

grant select, insert, update, delete on *.* to [email=test1@]test1@"%[/email]" identified by "abc123"; 如圖: 

mysql> grant select, insert, update, delete on *.* to ??? -> test1@"%" identified by "abc123"; query ok, 0 rows affected (0.03 sec) 

但例1增加的使用者是十分危險的,如某個人知道test1的密碼,那麼他就可以在internet上的任何一台電腦上登入你的mysql資料庫並對你的資料為所欲為了,解決辦法見例2。   

例2、增加乙個使用者test2密碼為abc123,讓他只可以在localhost上登入,並只可以對資料庫 mydb進行查詢、插入、修改、刪除的操作(localhost指本地主機,即mysql資料庫所在的那台主機),這樣使用者即使用知道test2的密碼,他也無法從internet上直接訪問資料庫,只能通mysql主機上來訪問了。 命令如下: 

grant select, insert, update,delete on mydb.* to test2@localhost identified by "abc123"; 如圖: 

mysql> grant select, insert, update, delete on mydb.* to 

??? -> [email=test2@localhost]test2@localhost[/email] identified by "abc123"; query ok, 0 rows affected (0.03 sec) 

如果你不想test2有密碼,可以再打乙個命令將密碼消掉。 命令如下: 

grant select, insert, update, delete on mydb.* to test2@localhost identified by "";   

三、修改密碼。  

格式:mysqladmin -u使用者名稱 -p舊密碼 password 新密碼  

例1:給root加個密碼ab123。首先在dos下進入目錄mysqlbin,然後鍵入以下命令  mysqladmin -uroot -password ab12  

注:因為開始時root沒有密碼,所以-p舊密碼一項就可以省略了。  例2:再將root的密碼改為abc345。  

mysqladmin -uroot -pab123 password abc345   

注意:你必須首先登入到mysql中,以下操作都是在mysql的提示符下進行的,而且每個命令以分號結束。

mysql基本命令總結 mysql基本命令總結

1.在ubuntu上安裝mysql sudo apt get install mysql server sudo apt get install mysql client 2.安裝結束後,用命令驗證是否安裝並啟動成功 sudo netstat tap grep mysql 通過上述命令檢查之後,如果...

mysql基本命令

第一招 mysql服務的啟動和停止 net stop mysql net start mysql 第二招 登陸mysql 語法如下 mysql u使用者名稱 p使用者密碼 鍵入命令mysql uroot p,回車後提示你輸入密碼,輸入12345,然後回車即可進入到mysql中了,mysql的提示符是...

mysql 基本命令

第一招 mysql服務的啟動和停止 net stop mysql net start mysql 第二招 登陸mysql 語法如下 mysql u使用者名稱 p使用者密碼 鍵入命令mysql uroot p,回車後提示你輸入密碼,輸入12345,然後回車即可進入到mysql中了,mysql的提示符是...