记一次mysql忘记密码并添加用户

记一次本地mysql忘记密码
/etc/init.d/mysqld stop

在my.cnf中加入这段
[mysqld]
skip-grant-tables

/etc/init.d/mysqld start
mysql -u root
flush privileges;

添加用户
//允许指定ip连接
create user '用户名'@'localhost' identified by '密码';
//允许所有ip连接(%表示所有ip)
create user 'demo'@'%' identified by 'demo';

授权
grant all privileges on 数据库名.表名 to '用户名'@'指定ip' identified by '密码' ;
// *表示所有
grant all privileges on *.* to 'demo'@'%' identified by 'demo' ;

设置操作权限
// 设置所有权限
grant all privileges on *.* to '用户名'@'指定ip' identified by '密码' WITH GRANT OPTION;
// 设置select权限
grant select on *.* to '用户名'@'指定ip' identified by '密码' WITH GRANT OPTION;
// 其他权限: select, insert, delete, update用都好隔开
grant select,insert on *.* to '用户名'@'指定ip' identified by '密码' WITH GRANT OPTION;
// 取消用户select权限
REVOKE select ON what FROM '用户名';

删除用户
DROP USER username@localhost;

修改后刷新
FLUSH PRIVILEGES;

上一篇:【DB笔试面试96】在MySQL中,下列SQL语句中,可为用户ZHANGSAN分配数据库USERDB表USERINFO的查询()


下一篇:Windows Phone8.1 SDK中的新控件