1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| # 1.关掉mysql服务
net stop mysql # 此处为win环境 linux为service stop mysql;
# 2.用cmd用管理员的方式进入到mysql的安装路径下的bin,执行:
mysqld --console --skip-grant-tables --shared-memory # 保留该窗口
# 3.重开cmd,无密码进入mysql:
mysql -u root
# 4.修改数据库并给root用户添加权限
use mysql;
update user set select_priv=‘Y’,Insert_priv=‘Y’,Update_priv=‘Y’,Delete_priv=‘Y’,Create_priv=‘Y’,Drop_priv=‘Y’,Reload_priv=‘Y’,File_priv=‘Y’,Grant_priv=‘Y’,References_priv=‘Y’,Index_priv=‘Y’,Alter_priv=‘Y’,Show_db_priv=‘Y’,Super_priv=‘Y’,Create_tmp_table_priv=‘Y’,Lock_tables_priv=‘Y’,Execute_priv=‘Y’,Repl_slave_priv=‘Y’,Repl_client_priv=‘Y’,Create_view_priv=‘Y’,Show_view_priv=‘Y’,Create_routine_priv=‘Y’,Alter_routine_priv=‘Y’,Create_user_priv=‘Y’,Event_priv=‘Y’,Trigger_priv=‘Y’,Create_tablespace_priv=‘Y’
WHERE user=‘root’;
# 5.刷新并退出:
flush privileges;
exit;
# 6.重启数据库
net restart mysql; # Linux为service mysql restart;
# 7.无密码登录
mysql -u root -p # 按[enter]在按[enter] 因为我们前面没有帮root用户设置密码,所有现在以root用户进入修改密码
# 8.修改密码
update user set password=password('123456')where user='root';
# 9.刷新用户权限并退出
flush privileges;
exit;
# 10.关闭步骤2中的mysqld
|