MySQL 許可權管理

2022-07-19 18:48:10 字數 3387 閱讀 7906

建立使用者:

mysql> create user root@'%' identified by 'mysqlpass123';

query ok, 0 rows affected (0.01 sec)

授權:

mysql> grant all on *.* to 'root'@'%';

query ok, 0 rows affected (0.00 sec)

重新整理許可權:

mysql> flush privileges;

query ok, 0 rows affected (0.00 sec)

刪除使用者:

mysql> drop user 'root'@'127.0.0.1';

query ok, 0 rows affected (0.00 sec)

mysql> delete from user where host='::1';

query ok, 1 row affected (0.01 sec)

grant all privileges on *.* to 'root'@'%' identified by '123456';

grant all privileges on slt_tppaml.* to 'slt_tppaml_w'@'%' identified by 'master_w';

grant select on slt_tppaml.* to 'slt_tppaml_r'@'%' identified by 'readonly';

flush privileges;

mysql設定密碼及修改密碼的方法

1.設定新密碼:(使用者初始沒有密碼)

# mysqladmin -uroot password '123456'

修改密碼:

# mysqladmin -uroot -p123456 password '888888'

2.用root 進入mysql後

mysql>set password for 'user'@'localhost' =password('mypass');

mysql>flush privileges;

例:將root@localhost帳號密碼設定為mysql!123。

mysql>set password for 'root'@'localhost'=password('mysql!123');

3.使用grant語句

mysql>grant all on *.* to 'root'@'localhost' identified by '你的密碼' with grant option ;

mysql>flush privileges;

4.進入mysql庫修改user表

mysql>use mysql;

mysql>update user set password=password('你的密碼') where user='root';

mysql>flush privileges;

通過命令列執行密碼修改:

# /usr/local/mysql/bin/mysql -uroot -p'mysqlpass' -e "update mysql.user set password=password('12345678') where host='127.0.0.1';"

mysql 5.7.17 修改使用者密碼:

-------------------------------------

mysql> update mysql.user set authentication_string=password('666666') where user='wk';

query ok, 1 row affected, 1 warning (0.06 sec)

rows matched: 1  changed: 1  warnings: 1

mysql> flush privileges;

query ok, 0 rows affected (0.00 sec)

mysql使用者管理

檢視使用者許可權:

mysql> show grants for root@localhost;

授權:

mysql許可權分為:全域性級別、資料庫級別、表級別、列級別,根據需要指定相應級別。

賦予root超級使用者權利許可權:

mysql> grant all privileges on *.* to root@'%' identified by '111111';

建立test全域性許可權並有授予別人的許可權:

mysql> grant all privileges on *.* to test@'%' identified by '222222' with grant option;

建立test使用者並賦予cacti庫所有許可權:

mysql> grant all privileges on cacti.* to test@'%' identified by '222222';

建立test使用者並賦予cacti庫某些許可權:

mysql> grant select,delete,update,create,drop on cacti.* to test@'%' identified by '222222';

建立test使用者並賦予cacti庫host表許可權:

mysql> grant all privileges on cacti.host to test@'%' identified by '222222';

撤銷使用者許可權:

mysql> revoke all on *.* from test;

mysql> revoke select on *.* from test@'%';

revoke語句只是取消使用者的許可權,沒有徹底刪除使用者,如果需要,可以用delete語句刪除使用者。

mysql> delete from mysql.user where user='test';

mysql> flush privileges;

多條件匹配刪除:

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

MySQL許可權管理

本文主要講述的是mysql grant命令的例項演示,文中的mysql grant命令的實際操作主要是在mysql 5.0 及以上的相關版本上執行,下面就是對其具體操作步驟的描述,望你在瀏覽之後會有所收穫。mysql 賦予使用者許可權命令的簡單格式可概括為 grant 許可權 on 資料庫物件 to...

mysql 許可權管理

1.新增使用者 方法一 create user wangda localhost identified by password 000000 說明 建立乙個本地的使用者,使用者名為 wangda 密碼為 000000 如果密碼為空,則 identified by password 000000 這個...

mysql許可權管理

mysqladmin u root p password leftpassword 無密碼的話直接回車 任意主機登入host換成 create user username host identified by password privileges all 代表所有許可權 表示全部的資料庫 gran...