关于mysql中root权限丢失的问题
发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,刚听一哥们说执行了一条语句:revoke all on *.* from root@localhost; --呵呵,当时到底是怎样的心理活动,这是怎样的恨。。。于是小菜就做了一个实验,心里感觉应该和密
千家信息网最后更新 2026年11月01日关于mysql中root权限丢失的问题刚听一哥们说执行了一条语句:revoke all on *.* from root@localhost; --呵呵,当时到底是怎样的心理活动,这是怎样的恨。。。
于是小菜就做了一个实验,心里感觉应该和密码丢失后跳过权限重新设置密码的解决方法是一样的,当然这只是思路,试试才知道。
首先停止数据库[root@mysql ~]#service mysql3306 stop --因为忘记密码所以只能停止服务的方式关闭数据库
Shutting down MySQL. [ OK ]
[root@mysql ~]#
[root@mysql ~]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/etc/my.cnf --skip-grant-tables & --跳过校验密码的方式启动数据库[2] 11254
[root@mysql ~]# 160330 16:56:22 mysqld_safe Logging to '/usr/local/mysql/log/err3306.log'.
160330 16:56:22 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
[root@mysql ~]# ps -ef | grep mysql --查看数据库已然启动
root 11254 6904 0 16:56 pts/2 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
mysql 11771 11254 0 16:56 pts/2 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --skip-grant-tables --log-error=/usr/local/mysql/log/err3306.log --pid-file=/usr/local/mysql/data/mysql.lz.com.pid --socket=/usr/local/mysql/mysqld3306.sock --port=3306
root 11795 6904 0 16:57 pts/2 00:00:00 grep mysql
[root@mysql ~]# /usr/local/mysql/bin/mysql --socket=/usr/local/mysql/mysqld3306.sock --port=3306 --不指定用户和密码直接登录数据库
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.17-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select user(); --默认为root用户登录
+--------+
| user() |
+--------+
| root@ |
+--------+
1 row in set (0.00 sec)
root@master 08:41:31 >grant all on *.* to 'root'@'localhost';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
在网上找到解决方法:
这个时候我们只需要
flush privileges 一下,在添加用户就OK了,
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
root@master 08:45:59 >grant all on *.* to 'ivan'@'localhost' identified by 'mysql321' with grant option;
Query OK, 0 rows affected (0.01 sec)
root@master 08:46:24 >flush privileges;
Query OK, 0 rows affected (0.01 sec)
root@master 08:46:31 >quit
Bye
[root@mysql data]# service mysql3306 stop
Shutting down MySQL..160409 08:46:39 mysqld_safe mysqld from pid file /usr/local/mysql/mysql3306.pid ended
[ OK ]
[1]+ Done /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/etc/my.cnf --skip-grant-tables
[root@mysql data]# ps -ef |grep msyql
root 62709 57953 0 08:46 pts/1 00:00:00 grep msyql
[root@mysql data]# service mysql3306 start
Starting MySQL.. [ OK ]
[root@mysql data]# /usr/local/mysql/bin/mysql -uivan -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.17-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
ivan@master 08:47:36 >grant all on *.* to 'root'@'localhost' with grant option;
Query OK, 0 rows affected (0.00 sec)
[root@mysql data]# /usr/local/mysql/bin/mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.5.17-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
root@master 08:49:33 >show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| c_test |
| ivan |
| mysql |
| performance_schema |
| test |
| webcat |
+--------------------+
至此一切正常。。。。。啊哈哈哈哈。。。。
于是小菜就做了一个实验,心里感觉应该和密码丢失后跳过权限重新设置密码的解决方法是一样的,当然这只是思路,试试才知道。
首先停止数据库[root@mysql ~]#service mysql3306 stop --因为忘记密码所以只能停止服务的方式关闭数据库
Shutting down MySQL. [ OK ]
[root@mysql ~]#
[root@mysql ~]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/etc/my.cnf --skip-grant-tables & --跳过校验密码的方式启动数据库[2] 11254
[root@mysql ~]# 160330 16:56:22 mysqld_safe Logging to '/usr/local/mysql/log/err3306.log'.
160330 16:56:22 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
[root@mysql ~]# ps -ef | grep mysql --查看数据库已然启动
root 11254 6904 0 16:56 pts/2 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
mysql 11771 11254 0 16:56 pts/2 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --skip-grant-tables --log-error=/usr/local/mysql/log/err3306.log --pid-file=/usr/local/mysql/data/mysql.lz.com.pid --socket=/usr/local/mysql/mysqld3306.sock --port=3306
root 11795 6904 0 16:57 pts/2 00:00:00 grep mysql
[root@mysql ~]# /usr/local/mysql/bin/mysql --socket=/usr/local/mysql/mysqld3306.sock --port=3306 --不指定用户和密码直接登录数据库
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.17-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select user(); --默认为root用户登录
+--------+
| user() |
+--------+
| root@ |
+--------+
1 row in set (0.00 sec)
root@master 08:41:31 >grant all on *.* to 'root'@'localhost';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
在网上找到解决方法:
这个时候我们只需要
flush privileges 一下,在添加用户就OK了,
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
root@master 08:45:59 >grant all on *.* to 'ivan'@'localhost' identified by 'mysql321' with grant option;
Query OK, 0 rows affected (0.01 sec)
root@master 08:46:24 >flush privileges;
Query OK, 0 rows affected (0.01 sec)
root@master 08:46:31 >quit
Bye
[root@mysql data]# service mysql3306 stop
Shutting down MySQL..160409 08:46:39 mysqld_safe mysqld from pid file /usr/local/mysql/mysql3306.pid ended
[ OK ]
[1]+ Done /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/etc/my.cnf --skip-grant-tables
[root@mysql data]# ps -ef |grep msyql
root 62709 57953 0 08:46 pts/1 00:00:00 grep msyql
[root@mysql data]# service mysql3306 start
Starting MySQL.. [ OK ]
[root@mysql data]# /usr/local/mysql/bin/mysql -uivan -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.17-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
ivan@master 08:47:36 >grant all on *.* to 'root'@'localhost' with grant option;
Query OK, 0 rows affected (0.00 sec)
[root@mysql data]# /usr/local/mysql/bin/mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.5.17-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
root@master 08:49:33 >show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| c_test |
| ivan |
| mysql |
| performance_schema |
| test |
| webcat |
+--------------------+
至此一切正常。。。。。啊哈哈哈哈。。。。
密码
数据
数据库
用户
方式
方法
登录
权限
只是
哥们
小菜
心理
思路
感觉
时候
至此
语句
这是
实验
服务
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
互联网加科技
广东万易互联网科技有限公司惠州分公司
互联网与科技发展
互联网 的科技创新
互联网科技作文
互联网科技网站
一五八零互联网科技
海南购全球互联网科技
深圳互联网科技怎么样
欧洲十大科技互联网公司
晓花互联网科技有限公司网址
上海科技产业互联网平台
启辰互联网科技
城市宝互联网科技有限公司
半导体行业属于互联网高科技类吗
长沙渺峰互联网科技有限公司
易租星互联网科技有限公司
科技互联网专业务虚会材料
互联网科技创业计划的风险分析
利用互联网等科技手段
博彦科技互联网金融
科技平台互联网
有马互联网科技
猫创互联网科技
丰台科技园 互联网公司
互联网金融中的现代科技
众安科技工业互联网合作
科技信息时代互联网发展
杭州科技互联网公司有哪些
瑞安市蟠桃会互联网科技有限公司