MySql學習筆記 登入 增加使用者 密碼更改

2021-04-20 02:06:20 字數 2551 閱讀 7877

一、連線mysql。

格式: mysql -h主機位址 -u使用者名稱 -p使用者密碼

例1:連線到本機上的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 增加使用者

3 增加使用者 注意 和上面不同,下面的因為是mysql環境中的命令,所以後面都帶乙個分號作為命令結束符 格式 grant select on 資料庫.to 使用者名稱 登入主機 identified by 密碼 第一種 增加乙個使用者test1密碼為abc,讓他可以在任何主機上登入,並對所有資料庫...

mysql 增加使用者

mysql 增加使用者 建議使用grant語句進行授權 grant 許可權 on 資料庫物件to 使用者 shell mysql user root mysql mysql grant all privileges on to monty localhost identified by someth...

MySQL增加使用者

格式 grant select on 資料庫.to 使用者名稱 登入主機 identified by 密碼 例1 增加乙個使用者test1密碼為abc,讓他可以在任何主機上登入,並對所有資料庫有查詢 插入 修改 刪除的許可權。首先用以root使用者連入mysql,然後鍵入以下命令 grant sel...