1.登入mysql
mysql -u root -p
2.新增使用者
insert into mysql.user(Host,User,Password) values("localhost","xxx",password("*"));
注釋:xxx為建立使用者名,*為使用者密碼
3.執行該句後,還需要重新整理權限表
flush privileges;
4.建立資料庫并賦予使用者權限
create database dbtest;
全部授權:
允許本地登入
grant all privileges on dbtest. to xxx@localhost identified by "";
允許任何主機登入
grant all privileges on dbtest. to xxx@'%' identified by "";
部分授權:
grant select,update on dbtest. to xxx@localhost identified by "**";
5.賦予權限,還需要再重新整理權限表
6.通過sql語句查詢出新增結果
select user,host,password from mysql.user;
7.删除使用者
delete from user where user=‘xxx’;
8.删除資料庫
drop database dbtest;
9.修改密碼
update mysql.user set password=password(‘新密碼’) where User='xxx' and Host='localhost';