1、登录mysql数据库
可能是环境变量没有配置mysql路径;
在环境变量path中加入
C:\Program Files\MySQL\MySQL Server 5.7\bin
1.使用管理员root登录数据库
mysql -uroot -p
2.切换到想使用的数据库
use database;
3.查看user表信息
select host,user from database.user;
FLUSH PRIVILEGES;//刷新权限,或者重启mysql服务生效权限
//4.删除root的所有权限
delete from user where Host='%' and User='root';
FLUSH PRIVILEGES;
//5.给某用户新增root权限
INSERT INTO `user`(`Host`, `User`, `Password`, `Select_priv`, `Insert_priv`, `Update_priv`, `Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`, `Shutdown_priv`, `Process_priv`, `File_priv`, `Grant_priv`, `References_priv`, `Index_priv`, `Alter_priv`, `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, `Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv`, `Create_view_priv`, `Show_view_priv`, `Create_routine_priv`, `Alter_routine_priv`, `Create_user_priv`, `Event_priv`, `Trigger_priv`, `Create_tablespace_priv`, `ssl_type`, `ssl_cipher`, `x509_issuer`, `x509_subject`, `max_questions`, `max_updates`, `max_connections`, `max_user_connections`, `plugin`, `authentication_string`, `password_expired`) VALUES ('1用户IP', 'root', '加密密码', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', 'Y', '', '', '', '', 0, 0, 0, 0, 'mysql_native_password', '', 'N');
FLUSH PRIVILEGES;
6.新建用户XX并赋予权限select
create user '用户名'@'%'identified by '密码';
grant select on database.* to 用户名;
FLUSH PRIVILEGES;
7.给XX用户新增某个表的增删改查权限
grant select, insert, update, delete on 数据库.表名 to 用户名@'%';
FLUSH PRIVILEGES;
8.更改密码
update user set password = password('新密码') where user ='用户名';
FLUSH PRIVILEGES;