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