重启后恢复MySQL root用户的完全权限

时间:2014-07-04 08:30:37

标签: mysql root

当我使用MySQL WorkBench在root上使用localhost用户登录并点击Users and Privileges时,我收到消息'您当前使用的帐户数量不足更改MySQL用户和权限的权限'。

关注the procedure in this answer我可以恢复root用户的完全权限:

  • 停止mysqld并使用--skip-grant-tables选项重启。
  • 仅使用mysqld连接到mysql服务器(即没有-p选项,可能不需要用户名。)
  • 在mysql客户端中发出以下命令:UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y' WHERE User='root'; FLUSH PRIVILEGES;
  • 运行GRANT ALL ON *.* TO 'root'@'localhost';

我可以关闭并重新打开MySQL Workbench并且我的root用户保留了它的完全权限,但是如果我重新启动计算机,我又回到了之前的不充分的特权状态,我必须重新执行整个过程。

如何在重启后恢复MySQL root用户的完全权限?

我的my.ini看起来像这样:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysqld]
# skip_grant_tables

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....


# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 
explicit_defaults_for_timestamp=TRUE

1 个答案:

答案 0 :(得分:2)

尝试稍微不同的操作顺序:

  1. 停止mysqld并使用mysqld --skip-grant-tables选项重新启动它。
  2. 使用:mysql连接到mysqld服务器(即没有-p选项,可能不需要用户名)。
  3. 在mysql客户端中发出以下命令:UPDATE mysql.user SET Grant_priv='Y',Super_priv='Y' WHERE User='root'; FLUSH PRIVILEGES;
  4. 重新启动您的mysql服务
  5. 现在运行GRANT ALL ON *.* TO 'root'@'localhost';
  6. 让我知道这是否有效。