mysql基础之忘掉密码解决办法及恢复root最高权限办法
如果忘记了mysql的root用户的密码,可以使用如下的方法,重置root密码。
方法一:
1、停止当前mysql进程
systemctl stop mariadb
2、mysql进程停止后,使用如下命名启动mysql,可以绕过用户验证
mysqld_safe --skip-grant-tables &
3、登录数据库(可以不输入密码登录了)
mysql -uroot
4、登录修改密码即可
update mysql.user set password=PASSWORD("new password") where user='root';
5、刷新后退出
flush privileges;
6、停止数据库后,按照正常的方式重启数据库,使用新密码登录
/usr/bin/mysqladmin -uroot shutdown -p123
systemctl start mariadb
mysql -u root -p123
方法二:
1、添加—skip-grant-tables
[root@ren7 ~]# vim /etc/my.cnf.d/server.cnf
[mysqld]
skip-grant-tables
2、重启数据库
[root@ren7 ~]# systemctl restart mariadb
3、登录数据库
[root@ren7 ~]# mysql -uroot #无密码也可以登录
4、修改密码
使用grant和set修改密码时会报错:
MariaDB [(none)]> grant all on *.* to root@'localhost' identified by '123';
ERROR 1290 (HY000): The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement
MariaDB [(none)]> set password for root@localhost=password('123');
ERROR 1290 (HY000): The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement
可以使用update来修改密码:
MariaDB [(none)]> update mysql.user set password=password('123') where user='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0 MariaDB [(none)]> \q
Bye
5、注销掉配置文件中的选项
[root@ren7 ~]# vim /etc/my.cnf.d/server.cnf
[mysqld]
#skip-grant-tables
6、重启数据库
[root@ren7 ~]# systemctl restart mariadb
7、再次登录
[root@ren7 ~]# mysql -uroot -p123
恢复root用户超级权限的方法
前面的步骤和修改密码的一致,只是在进入数据库后需要执行以下命令:
insert into user set user='root',ssl_cipher=''x509_issuer='',x509_subject='';(可省)
update mysql.user set grant_priv=’y’,super_priv=’y’ where user=’root’;
flush privileges #刷新缓冲区
grant all on *.* to ‘root’@’localhost’; #授权
select * from mysql.user\G; #查看用户权限
之后退出,重新登录即可。
mysql.user里的其它内容:
update user set Host='localhost',select_priv='y', insert_priv='y',update_priv='y', Alter_priv='y',delete_priv='y',create_priv='y',drop_priv='y',reload_priv='y',shutdown_priv='y',Process_priv='y',file_priv='y',grant_priv='y',References_priv='y',index_priv='y',create_user_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' where user='root';
最新文章
- MySQL数据表range分区例子
- 浏览器对象模型BOM小结
- php $_SERVER中的SERVER_NAME 和HTTP_HOST的区别
- nodejs-helloword案例
- BZOJ 3339 &; 莫队+";所谓的暴力";
- android知识体系
- ERP仓库管理系统查询(十)
- php 函数ignore_user_abort()
- window内存管理与内存原理
- Linux系统启动过程介绍
- LinuxMint(Ubuntu)安装文泉驿家族黑体字
- 弹窗滑动,造成body跟随滑动解决办法
- GNOME 系统设置
- Linux下的搜索查找命令的详解(which)
- phpStorm使用技巧总结
- 2018.10.2浪在ACM 集训队第三次测试赛
- Node内核基本自带模块fs 文件的读写
- HDU 6095 17多校5 Rikka with Competition(思维简单题)
- 009.Zabbix幻灯片展示
- html中载入自执行getElementById(";xx";)得到null