標籤:
一 使用者添加
- 通過insert 方式添加使用者
insert into mysql.user(Host,User,Password) values("localhost","sa",password("admin123"))
出現異常:
DBCException: SQL Error [1364] [HY000]: Field ‘ssl_cipher‘ doesn‘t have a default value
java.sql.SQLException: SQLException: Field ‘ssl_cipher‘ doesn‘t have a default value
異常原因:禁止通過insert 方式修改使用者user
解決方式:在my.cnf中有這樣一條語句:sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES。
將改為:sql_mode=NO_ENGINE_SUBSTITUTION。
重啟伺服器。
- 通過命令create
CREATE USER ‘sa‘@‘127.0.0.1‘ IDENTIFIED BY "admin123";
192.168.189.%:ip可以通過使用萬用字元來限制使用者的ip
二 . 使用者刪除
DELETE FROM user WHERE User=”sa” and Host=”localhost”;
flush privileges;
三. 修改密碼
update mysql.user set password=password(‘新密碼’) where
User=”sa” and Host=”localhost”;
flush privileges;
四. 使用者授權
create database cplusplusDB;
//授權cplusplus使用者擁有cplusplusDB資料庫的所有許可權。
grant all privileges on cplusplusDB.* to [email protected] identified
by ‘admin123‘;
//重新整理系統許可權表
mysql>flush privileges;
五. 部分授權
grant select,update on cplusplusDB.* to [email protected]
identified by ‘admin123‘;
//重新整理系統許可權表。
flush privileges;
Mysql帳號管理