在尝试浏览或了解有关mysql phpmyadmin中用户的更多信息时,我意外删除了用户root的 PRIVILEGES 。现在我无法创建新数据库,新用户等。如何将 PRIVILEGES 再次恢复为用户root
Tried
USE mysql;
UPDATE user SET Grant_priv='1' WHERE User='root';
FLUSH PRIVILEGES;
Getting
错误 SQL查询:
USE mysql;
MySQL说:文档
1044 - 用户'root'@'localhost'拒绝访问数据库'mysql'
Tried
UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y' WHERE User='root';
FLUSH PRIVILEGES;
GRANT ALL ON *.* TO 'root'@'localhost';
Getting
错误 SQL查询:
UPDATE mysql.user SET Grant_priv ='Y', Super_priv ='Y'WHERE User ='root';
MySQL说:文档
1142 - UPDATE命令拒绝用户'root'@'localhost'表'user'
UPDATE
我尝试创建新用户
CREATE USER 'user'@'localhost' IDENTIFIED BY 'user';
我收到此错误
1227 - 拒绝访问;您需要(至少一个)此操作的CREATE USER权限
tried
GRANT ALL PRIVILEGES ON * . * TO 'root'@'localhost' IDENTIFIED BY 'qwe';
getting
1045 - 用户'root'@'localhost'拒绝访问(使用密码:YES)
任何想法都表示赞赏。
答案 0 :(得分:2)
如果你错误地删除了root用户,你可以做一件事:
在mysql命令行输入:use mysql; 然后执行此查询:
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`, `ssl_type`, `ssl_cipher`, `x509_issuer`, `x509_subject`, `max_questions`, `max_updates`, `max_connections`, `max_user_connections`) values('localhost','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','','','','','0','0','0','0');
然后重启mysqld
答案 1 :(得分:0)
对于MariaDB 5.5.56以及其他人,命令必须是:
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`) values('localhost','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');
添加Event_priv
,Trigger_priv
和Create_tablespace_priv
。