mysql 建立使用者 分配許可權

2021-08-09 03:46:15 字數 1746 閱讀 7148

mysql建立使用者的方法分成三種:insert user表的方法、create user的方法、grant的方法。

1、通過create user命令進行建立使用者

指令碼:create user 'username'@'host' [identified by 'password'] 其中密碼是可選項;

例子:create user 'test'@'127.0.0.1' identified by "123";

create user 'test'@'127.0.0.%' identified by "123";

create user 'test'@' %' ;

說明:該方法建立出來的使用者只有連線資料庫的許可權,需要後續繼續授權;

2、通過grant命令建立使用者

個人習慣一般用這種方法進行建立使用者,當資料庫存在使用者的時候grant會對使用者進行授權,但當資料庫不存在該使用者的時候,就會建立

相應的使用者並進行授權。(說明上面那步是多餘的)

指令碼:grant on [object] [identified by 'password']

[with grant option];

max_queries_per_hour count

max_updates_per_hour count

max_connections_per_hour count

max_user_connections count

說明:priv代表許可權select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file等14個許可權

例子:mysql>grant select,insert,update,delete,create,drop on test.hr to [email protected] identified by '123';

說明:給主機為127.0.0.1的使用者test分配可對資料庫test的hr表進行select,insert,update,delete,create,drop等操作的許可權,並設定口令

為123。

mysql>grant all privileges on test.* to [email protected] identified by '123';

說明:給主機為127.0.0.1的使用者test分配可對資料庫test所有表進行所有操作的許可權,並設定口令為123。

mysql>grant all privileges on *.* to

test

@127.0.0.1 identified by '123';

說明:給主機為127.0.0.1的使用者test分配可對所有資料庫的所有表進行所有操作的許可權,並設定口令為123。

mysql>grant all privileges on *.* to test

@127.0.0.1 identified by '123';

說明:使用者test分配可對所有資料庫的所有表進行所有操作的許可權,並設定口令為123。

3、直接向mysql.user表插入記錄

因為資料庫的使用者資訊都是儲存在mysql.user這張表的,所以直接對該錶進行插入語句,即可完成使用者的建立;

mysql> insert into user (host,user,password) values ('%','test',password('123'));

4、完成使用者的建立後,請記得重新整理系統許可權表;

mysql>flush privileges;

mysql建立使用者並分配許可權

mysql u root p 提示輸入密碼,輸入密碼後回車,進入mysql命令列 create user test identified by 123456 test為使用者名稱,123456為密碼,表示任何電腦都可以訪問,如果只為本地使用者建立,則 改為localhost grant select...

Mysql命令建立使用者分配許可權

1 建立乙個資料庫abc mysql create database abc 2 選擇你所建立的資料庫 mysql use abc database changed 3 建立乙個資料庫表 首先看現在你的資料庫中存在什麼表 mysql show tables empty set 0.00 sec my...

MYSQL建立使用者分配許可權筆記

使用者管理 mysql是乙個多使用者的資料庫系統,按許可權,使用者可以分為兩種 root使用者超級管理員和root使用者建立的普通使用者 mysql建立使用者 語法 create user 使用者名稱 identified by 密碼 檢視使用者 select user,host from user...