修改密码
use mysql;
update user set authentication_string=password('新的密码') where user='root' and Host='localhost';
如果出现下面的提示,则说明密码太过简单
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
可以换个复杂点的密码。或者修改一下密码策略
set global validate_password_policy=LOW;
现在再回到第一步重新修改密码集合
授权访问
全局授权
比如给root授予所有权利
grant all privileges on *.* to root@'%' identified by '密码' with grant option;
flush privileges;
分析:
all privileges 表示所有的特权
第一个*表示任意数据库
第二个*表示任意表
root 表示用户名为root
% 表示任意ip,这里可以换成具体的ip。
identified by 表示用某个密码来认证。
flush privileges; 表示刷新权限,使上面的操作立刻生效。
局部授权
指定用户名和数据库
grant all privileges on gdmm_db.* to gdmm@'%' identified by '密码' with grant option;
将gdmm_db数据库的所有权限授给gdmm用户。
指定具体的权限
grant create,alter,drop,insert,delete,update,select on gdmm_db.* to test@'%' identified by '密码' with grant option;
create 建立新的数据库或数据表
alter 修改已存在的数据表(例如增加/删除列)
drop 删除表或数据库
insert 增加表的数据
delete 删除表的数据
update 修改表中已存在的数据
select 显示/搜索表的数据
回收权限
回收test用户的所有权限
revoke all privileges on *.* from 'test';
用户管理
删除用户
mysql> select host,user from user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| % | gdmm |
| % | root |
| % | test |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+
6 rows in set (0.00 sec)
mysql> drop user 'test'@'%;
Query OK, 0 rows affected (0.00 sec)
重命名
rename user 'test1'@'%' to 'test2'@'%';