mysql 建立使用者並授權
阿新 • • 發佈:2019-01-24
轉載地址 http://www.cnblogs.com/shindo/p/5146168.html
測試環境:linux 和Mysql 5.5.35
一、新建使用者
//登入Mysql
@>mysql -u root -p
@>密碼
//建立使用者
mysql> insert into mysql.user(Host,User,Password)
values('localhost','xdev',password('xdev123'));
//刷新系統許可權表
mysql>flush privileges;
這樣就建立了一個名為:xdev密碼為:xdev123 的使用者。
二、登入測試
mysql>exit;
@>mysql -u cplusplus -p
@>輸入密碼
mysql>登入成功
三、使用者授權
//登入MYSQL
@>mysql -u root -p
@>密碼
//首先為使用者建立一個數據庫(tz_ebank)
mysql>create database tz_ebank;
//授權xdev使用者使用密碼xdev123擁有tz_ebank資料庫的所有許可權,並從任何主機連線的話。
mysql >grant all privileges on tz_ebank.* to [email protected]‘%’ identified by ‘xdev123' with grant obtion; ---如果你想限制使用者只能從192.168.1.222的主機連線到mysql伺服器,以上的授權語句可做如下修改: ---mysql>grant all privileges on tz_ebank.* to [email protected]
mysql>其它操作
四、部分授權
mysql>grant select,update on tz_ebank.* to [email protected] identified by ‘ xdev123';
//刷新系統許可權表。
mysql>flush privileges;
五、刪除使用者
@>mysql -u root -p
@>密碼
mysql>delete from user where user=‘xdev’;
mysql>flush privileges;
六、刪除資料庫
mysql>drop database tz_ebank;
七、修改密碼
@>mysql -u root -p
@>密碼
mysql>update mysql.user set password=password(‘新密碼’) where User='xdev' and Host='localhost';
mysql>flush privileges;