如何将所有权限恢复给 MySQL 中的 root 用户?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1708826/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get all privileges back to the root user in MySQL?
提问by Steven
I am using MySQL. My root user doesn't have all privileges. How can I get all privileges back to the root user? How to do it step by step?
我正在使用 MySQL。我的 root 用户没有所有权限。如何将所有权限恢复给 root 用户?如何一步一步做到?
回答by Joe
This worked for me on Ubuntu:
这在 Ubuntu 上对我有用:
Stop MySQL server:
停止 MySQL 服务器:
/etc/init.d/mysql stop
Start MySQL from the commandline:
从命令行启动 MySQL:
/usr/sbin/mysqld
In another terminal enter mysql and issue:
在另一个终端输入 mysql 并发出:
grant all privileges on *.* to 'root'@'%' with grant option;
You may also want to add
您可能还想添加
grant all privileges on *.* to 'root'@'localhost' with grant option;
and optionally use a password as well.
并可选择使用密码。
flush privileges;
and then exit your MySQL prompt and then kill the mysqld server running in the foreground. Restart with
然后退出您的 MySQL 提示符,然后终止在前台运行的 mysqld 服务器。重启
/etc/init.d/mysql start
回答by Kin Shu
If you facing grant permission access denied problem, you can try mysql_upgrade to fix the problem:
如果您面临授予权限访问被拒绝的问题,您可以尝试使用 mysql_upgrade 来解决该问题:
/usr/bin/mysql_upgrade -u root -p
Login as root:
以 root 身份登录:
mysql -u root -p
Run this commands:
运行此命令:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost';
mysql> FLUSH PRIVILEGES;
回答by Kaleb Brasee
Log in as root, then run the following MySQL commands:
以 root 身份登录,然后运行以下 MySQL 命令:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost';
FLUSH PRIVILEGES;