MySQL的root密码忘记或丢失的解决方法一例
发表于:2025-01-24 作者:千家信息网编辑
千家信息网最后更新 2025年01月24日,-bash-4.2$ service mysql statusSUCCESS! MySQL running (2670)-bash-4.2$ mysql -u root -pEnter passwor
千家信息网最后更新 2025年01月24日MySQL的root密码忘记或丢失的解决方法一例-bash-4.2$ service mysql status
SUCCESS! MySQL running (2670)
-bash-4.2$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
以下是密码忘记的解决方法:
修改MySQL的参数设置:
# vi /etc/my.cnf
在[mysqld]的段最后一行加上一句:skip-grant-tables
例如:
[mysqld]
........................
log-bin=mysql-bin
innodb_data_file_path = ibdata1:12M;ibdata2:100M;ibdata3:300M:autoextend
innodb_file_per_table=on
max_connections=500
skip-grant-tables --新增加行
保存并且退出vi.
重启MySQL服务:
[root@chenfeng subsys]# service mysql restart
Shutting down MySQL. SUCCESS!
Starting MySQL. SUCCESS!
-bash-4.2$ mysql --不用输密码直接登录
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.15-log Source distribution
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| chenfeng |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
MySQL [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MySQL [mysql]> UPDATE user SET Password = password ('12345678') WHERE User ='root'; --修改为新密码12345678
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
MySQL [mysql]>
MySQL [mysql]> flush privileges; --刷新一下权限表
Query OK, 0 rows affected (0.00 sec)
MySQL [mysql]> quit
Bye
将MySQL的参数设置修改回来:
# vi /etc/my.cnf
将刚才在[mysqld]的段中最后一行加上的skip-grant-tables删除,然后保存退出。
重启MySQL服务:
[root@chenfeng subsys]# service mysql restart
Shutting down MySQL. SUCCESS!
Starting MySQL. SUCCESS!
重新用新密码登录:
-bash-4.2$ mysql -u root -p12345678 --12345678为新密码
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.15-log Source distribution
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MySQL [mysql]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| chenfeng |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
MySQL [mysql]>
SUCCESS! MySQL running (2670)
-bash-4.2$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
以下是密码忘记的解决方法:
修改MySQL的参数设置:
# vi /etc/my.cnf
在[mysqld]的段最后一行加上一句:skip-grant-tables
例如:
[mysqld]
........................
log-bin=mysql-bin
innodb_data_file_path = ibdata1:12M;ibdata2:100M;ibdata3:300M:autoextend
innodb_file_per_table=on
max_connections=500
skip-grant-tables --新增加行
保存并且退出vi.
重启MySQL服务:
[root@chenfeng subsys]# service mysql restart
Shutting down MySQL. SUCCESS!
Starting MySQL. SUCCESS!
-bash-4.2$ mysql --不用输密码直接登录
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.15-log Source distribution
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| chenfeng |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
MySQL [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MySQL [mysql]> UPDATE user SET Password = password ('12345678') WHERE User ='root'; --修改为新密码12345678
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
MySQL [mysql]>
MySQL [mysql]> flush privileges; --刷新一下权限表
Query OK, 0 rows affected (0.00 sec)
MySQL [mysql]> quit
Bye
将MySQL的参数设置修改回来:
# vi /etc/my.cnf
将刚才在[mysqld]的段中最后一行加上的skip-grant-tables删除,然后保存退出。
重启MySQL服务:
[root@chenfeng subsys]# service mysql restart
Shutting down MySQL. SUCCESS!
Starting MySQL. SUCCESS!
重新用新密码登录:
-bash-4.2$ mysql -u root -p12345678 --12345678为新密码
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.6.15-log Source distribution
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MySQL [mysql]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| chenfeng |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.00 sec)
MySQL [mysql]>
新密
密码
一行
参数
服务
登录
方法
不用
权限
加行
上一
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
浙江省网络安全示范点
64核心服务器
重庆社区团购软件开发
格式还原数据库
服务器业务地址和管理地址区别
小学网络安全宣传活动的总结
浙江正规软件开发诚信推荐
习颂互联网科技
软件开发项目都有什么
戴尔服务器带tesla显卡
杭州逻迅网络技术有限公司
网络安全和信息化的三个核心技术
上海科技和互联网
上海软件开发公司服务好得
苹果app服务器部署
平板电脑输入法软件开发
5g软件开发面试
视觉传感器网络技术
网络安全的主要威胁ppt
无锡市软件开发哪个公司好
软件开发评审
实用网络技术期末考试题库
服务器业务地址和管理地址区别
数据库表关系图怎么设置
德宏软件开发公司
文件服务器发布图片
人防 网络安全意识深入人心
高淳区网络技术服务创新服务
杭州软度网络技术有限公司
检察院的网络技术要求