欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Mysql中新建用戶及授權(quán)的方法分享

 更新時(shí)間:2016年07月15日 11:33:50   投稿:hebedich  
這篇文章給大家匯總介紹了Mysql中新建用戶及授權(quán)的方法,首先介紹的是作者自己的項(xiàng)目經(jīng)歷,后面附上了參考文章,希望能對(duì)大家學(xué)習(xí)mysql有所幫助。

在項(xiàng)目開發(fā)的過程中可能需要開放自己的數(shù)據(jù)庫給別人,但是為了安全不能自己服務(wù)器里其他數(shù)據(jù)庫同時(shí)開放。那么可以新建一個(gè)用戶,給該用戶開放特定數(shù)據(jù)庫權(quán)限

測試環(huán)境:Centos 6.3和Mysql 5.3

一、新建用戶

復(fù)制代碼 代碼如下:

//登錄MYSQL
@>mysql -u root -p
@>密碼
//創(chuàng)建用戶
mysql> insert into mysql.user(Host,User,Password) values("localhost","cplusplus",password("cplusplus.me"));
//刷新系統(tǒng)權(quán)限表
mysql>flush privileges;

這樣就創(chuàng)建了一個(gè)名為:cplusplus 密碼為:cplusplus.me 的用戶。

二、登錄測試

mysql>exit;
@>mysql -u cplusplus -p
@>輸入密碼
mysql>登錄成功

三、用戶授權(quán)

//登錄MYSQL
@>mysql -u root -p
@>密碼
//首先為用戶創(chuàng)建一個(gè)數(shù)據(jù)庫(cplusplusDB)
mysql>create database cplusplusDB;
//授權(quán)cplusplus用戶擁有cplusplusDB數(shù)據(jù)庫的所有權(quán)限。
>grant all privileges on cplusplusDB.* to cplusplus@localhost identified by 'cplusplus.me';
//刷新系統(tǒng)權(quán)限表
mysql>flush privileges;
mysql>其它操作

四、部分授權(quán)

mysql>grant select,update on cplusplusDB.* to cplusplus@localhost identified by 'cplusplus.me';
//刷新系統(tǒng)權(quán)限表。
mysql>flush privileges;

五、刪除用戶

@>mysql -u root -p
@>密碼
mysql>DELETE FROM user WHERE User="cplusplus" and Host="localhost";
mysql>flush privileges;

六、刪除數(shù)據(jù)庫

mysql>drop database cplusplusDB;

七、修改密碼

@>mysql -u root -p
@>密碼
mysql>update mysql.user set password=password('新密碼') where User="cplusplus" and Host="localhost";
mysql>flush privileges;

給大家分享一則網(wǎng)友的經(jīng)驗(yàn):

1.新建用戶

用戶root權(quán)限登錄mysql,新建一個(gè)和數(shù)據(jù)庫同名的用戶

mysql> INSERT INTO mysql.user(Host,User,Password) VALUES('localhost', 'sun', password('sun123456'));

刷新系統(tǒng)權(quán)限表

mysql> FLUSH PRIVILEGES;

如果報(bào)錯(cuò)

#1364 – Field ‘ssl_cipher' doesn't have a default value

修改MySQL配置文件linux系統(tǒng)為my.cnf,windows系統(tǒng)為my.ini

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

修改為

sql_mode=NO_ENGINE_SUBSTITUTION

重啟MySQL服務(wù)

2.為用戶授權(quán)

mysql> GRANT ALL ON sun.* to sun@localhost identified BY 'sun123456';
mysql> FLUSH PRIVILEGES;

相關(guān)文章

最新評(píng)論