mac mysql 新建使用者 MySql建立使用者

2021-10-17 21:11:12 字數 2331 閱讀 4380

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

一、賬號名稱的構成方式

賬號的組成方式:使用者名稱+主機(所以可以出現重複的使用者名稱,跟其他的資料庫不一樣)

使用者名稱:16字元以內.

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

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

例子:create user '[email protected]' identified by "123";

create user '[email protected].%' identified by "123";

create user 'john@' ;

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

注意:使用者與@後主機位址是一體的,用乙個分號連線,否則會報錯,error 1396 (hy000): operation create user failed for 'remote'@'%'

三、通過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';

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

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

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

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

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

mysql>grant all privileges on . to john@localhost identified by '123';

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

mysql>grant insert,delete,update,select on . to 'saas'@'%' identified by '123';

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

檢視許可權:

show grants for你的使用者;

show grants forroot@'localhost';

show grants for [email protected];

show createdatabase dbname; 這個可以看到建立資料庫時用到的一些引數。

showcreatetabletickets; 可以看到建立表時用到的一些引數

撤銷許可權:

revoke all on . from dba@localhost;

四、直接向mysql.user表插入記錄(該方法個人很少用)

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

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

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

mysql>flush privileges;

Mac mysql改使用者密碼

前段時間和幾個朋友一起做個小專案,用svn的時候發現大家mysql資料庫密碼不一樣,網上搜了好長時間總是沒發現能一次管用的方法 也可能是我操作不當哈 又到谷歌去搜了幾個印度人的帖子,發現基本谷歌搜出來的都是同一種方法 基本都是印度人 親測之後發現很有用,幫幾個同樣用mac的朋友也改了,拿出來和大家分...

mac mysql重置root使用者密碼

蘋果機安裝的mysql後,設定初始密碼 引子 在蘋果機上安裝的mysql之後,通過mysqlworkbench登入本地資料連線,發現沒有密碼,而在安裝mysql的過程中,是沒有設定過密碼的其實,剛剛安裝完,是有乙個介面,分配了乙個初始化的密碼,可能大家都像我一樣,直接點選就跳過去了,沒有過儲存,所以...

新建oracle使用者

啟動oracle的控制台,並彈出add database to tree對話方塊,並填寫 hostname 本機ip sid ora9i 安裝之前配置好的 port number 1521 然後在connect database介面上輸入 username sy an password oem te...