Mysql建立 刪除使用者,更改使用者許可權命令

2021-07-22 19:26:07 字數 1962 閱讀 7492

mysql中新增使用者,新建資料庫,使用者授權,刪除使用者,修改密碼(注意每行後邊都跟個;表示乙個命令語句結束):

1.新建使用者

@>mysql -u root -p

@>密碼

mysql> insert into mysql.user(host,user,password) values("localhost","test",password("1234"));

這樣就建立了乙個名為:test 密碼為:1234 的使用者。

注意:此處的"localhost",是指該使用者只能在本地登入,不能在另外一台機器上遠端登入。如果想遠端登入的話,將"localhost"改為"%",表示在任何一台電腦上都可以登入。也可以指定某台機器可以遠端登入。

mysql>exit;

@>mysql -u test -p

@>輸入密碼

mysql>登入成功

2.為使用者授權

授權格式:grant 許可權 on 資料庫.* to 使用者名稱@登入主機 identified by "密碼"; 

@>mysql -u root -p

@>密碼

mysql>create database testdb;

mysql>grant all privileges on testdb.* to test@localhost identified by '1234';

mysql>flush privileges;//重新整理系統許可權表

格式:grant 許可權 on 資料庫.* to 使用者名稱@登入主機 identified by "密碼"; 

mysql>grant select,update on testdb.* to test@localhost identified by '1234';

mysql>flush privileges; //重新整理系統許可權表

mysql>grant select,delete,update,create,drop on *.* to test@"%" identified by "1234";

//test使用者對所有資料庫都有select,delete,update,create,drop 許可權。

//@"%" 表示對所有非本地主機授權,不包括localhost。(localhost位址設為127.0.0.1,如果設為真實的本地位址,不知道是否可以,沒有驗證。)

//對localhost授權:加上一句grant all privileges on testdb.* to test@localhost identified by '1234';即可。

3.刪除使用者

@>mysql -u root -p

@>密碼

mysql>delete from user where user='test' and host='localhost';

mysql>flush privileges;

mysql>drop database testdb; //刪除使用者的資料庫

刪除賬戶及許可權:>drop user 使用者名稱@'%';

>drop user 使用者名稱@ localhost; 

4.修改指定使用者密碼

@>mysql -u root -p

@>密碼

mysql>update mysql.user set password=password('新密碼') where user="test" and host="localhost";

mysql>flush privileges;

5.列出所有資料庫

mysql>show database;

6.切換資料庫

mysql>use '資料庫名';

7.列出所有表

mysql>show tables;

8.顯示資料表結構

mysql>describe 表名;

9.刪除資料庫和資料表

mysql>drop database 資料庫名;

mysql>drop table 資料表名;

mysql更改使用者密碼

1 mysqladmin mysqladmin u username p password new password 2 手工更新授權表 mysql update user set password password new password where user username mysql fl...

MySql更改使用者密碼

1.use mysql show tables 檢視mysql資料庫中的表,會看到乙個user表。select from user 檢視一下這個表中是否有root使用者,如果有 update user set password password 123 where user root 更改root使...

MySQL如何更改使用者密碼

在mysql中,可以使用3種不同的語句更改使用者帳戶密碼 1 update 2 set password 3 alter user 但在更改帳戶密碼之前,應記住兩件非常重要的事情 1 要更改密碼的使用者帳戶詳細資訊。2 正在更改密碼的使用者正在使用該應用程式,因為如果在不更改應用程式的連線字串的情況...