首页 > 数据库技术 > 详细

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

时间:2021-06-16 14:28:01      阅读:15      评论:0      收藏:0      [点我收藏+]

记一次本地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;

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

原文:https://blog.51cto.com/u_96521/2908189

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!