首页 数据库 mysql教程 CentOS系统重置MySQL数据库密码

CentOS系统重置MySQL数据库密码

Jun 07, 2016 pm 03:01 PM
c centos mysql 学习 密码 数据库 系统 重置

学习CentOS Linux的时候经常会忘记各种密码,本文主要说明在使用CentOS的过程中,忘记MySQL数据库密码的解决办法。 第一步:通过如下代码,停止MySQL服务器的运行 01 02 [root@CentOs5 ~]# service mysqld stop Stopping MySQL: [ OK ] 第二步:使用 “–ski

学习CentOS Linux的时候经常会忘记各种密码,本文主要说明在使用CentOS的过程中,忘记MySQL数据库密码的解决办法。<br> 第一步:通过如下代码,停止MySQL服务器的运行

01

02

[root@CentOs5 ~]# service mysqld stop

Stopping MySQL:                                            [  OK  ]

01 02

[root@CentOs5 ~]# service mysqld stop

01

02

03

[root@CentOs5 ~]# mysqld_safe --skip-grant-tables &amp;

[1] 23810

[root@CentOs5 ~]# Starting mysqld daemon with databases from /var/lib/mysql

Stopping MySQL:                                            [  OK  ]

第二步:使用 “–skip-grant-tables”参数重新启动mysql

01

02

03

04

05

[root@CentOs5 ~]# mysql -u root

Welcome to the MySQL monitor.  Commands end with ; or g.

Your MySQL connection id is 1

Server version: 5.0.77 Source distribution

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

01

02

03

01

02

03

04

mysql> 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

[root@CentOs5 ~]# mysqld_safe --skip-grant-tables &amp;

[1] 23810

[root@CentOs5 ~]# Starting mysqld daemon with databases from /var/lib/mysql

01

02

03

mysql> update user set password=password('admin123') where user='root';

Query OK, 1 row affected (0.04 sec)

Rows matched: 1  Changed: 1  Warnings: 0

第三步:用帐号登录MySQL

01

02

03

04

mysql> flush previleges;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'previleges' at line 1

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

01

02

03

01

02

mysql> quit

Bye

04 05
[root@CentOs5 ~]# mysql -u root Welcome to the MySQL monitor.  Commands end with ; or g. Your MySQL connection id is 1 Server version: 5.0.77 Source distribution Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
第四步:改变用户数据库表
01 02 03 04 mysql> 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
第五步:修改密码,记得密码要用password()函数进行加密,一定不要忘记!不然,
01 02 03 mysql> update user set password=password('admin123') where user='root'; Query OK, 1 row affected (0.04 sec) Rows matched: 1  Changed: 1  Warnings: 0
第六步:刷新权限表
01 02 03 04 mysql> flush previleges; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'previleges' at line 1 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
第七步:退出mysql
01 02 mysql> quit Bye

第八步:对mysql进行重启

01

02

03

04

05

06

[root@CentOs5 ~]# service mysqld restart;

STOPPING server from pid file /var/run/mysqld/mysqld.pid

100421 13:44:03  mysqld ended

Stopping MySQL:                                            [  OK  ]

Starting MySQL:                                            [  OK  ]

[1]+  Done                    mysqld_safe --skip-grant-tables

01 02

03

04

01

02

03

04

05

06

07

08

09

[root@CentOs5 ~]# mysql -u root -p

Enter password: admin123

Welcome to the MySQL monitor.  Commands end with ; or g.

Your MySQL connection id is 2

Server version: 5.0.77 Source distribution

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

mysql> quit

Bye

[root@CentOs5 ~]#

<br>

05 06
[root@CentOs5 ~]# service mysqld restart; STOPPING server from pid file /var/run/mysqld/mysqld.pid 100421 13:44:03  mysqld ended Stopping MySQL:                                            [  OK  ] Starting MySQL:                                            [  OK  ] [1]+  Done                    mysqld_safe --skip-grant-tables
第九步:用更改过的密码重新登录即可。
01 02 03 04 05 06 07 08 09 [root@CentOs5 ~]# mysql -u root -p Enter password: admin123 Welcome to the MySQL monitor.  Commands end with ; or g. Your MySQL connection id is 2 Server version: 5.0.77 Source distribution Type 'help;' or 'h' for help. Type 'c' to clear the buffer. mysql> quit Bye [root@CentOs5 ~]# <br>
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解锁Myrise中的所有内容
4 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

MySQL:初学者的数据管理易用性 MySQL:初学者的数据管理易用性 Apr 09, 2025 am 12:07 AM

MySQL适合初学者使用,因为它安装简单、功能强大且易于管理数据。1.安装和配置简单,适用于多种操作系统。2.支持基本操作如创建数据库和表、插入、查询、更新和删除数据。3.提供高级功能如JOIN操作和子查询。4.可以通过索引、查询优化和分表分区来提升性能。5.支持备份、恢复和安全措施,确保数据的安全和一致性。

忘记数据库密码,能在Navicat中找回吗? 忘记数据库密码,能在Navicat中找回吗? Apr 08, 2025 pm 09:51 PM

Navicat本身不存储数据库密码,只能找回加密后的密码。解决办法:1. 检查密码管理器;2. 检查Navicat的“记住密码”功能;3. 重置数据库密码;4. 联系数据库管理员。

navicat premium怎么创建 navicat premium怎么创建 Apr 09, 2025 am 07:09 AM

使用 Navicat Premium 创建数据库:连接到数据库服务器并输入连接参数。右键单击服务器并选择“创建数据库”。输入新数据库的名称和指定字符集和排序规则。连接到新数据库并在“对象浏览器”中创建表。右键单击表并选择“插入数据”来插入数据。

Navicat for MariaDB如何查看数据库密码? Navicat for MariaDB如何查看数据库密码? Apr 08, 2025 pm 09:18 PM

Navicat for MariaDB 无法直接查看数据库密码,因为密码以加密形式存储。为确保数据库安全,有三个方法可重置密码:通过 Navicat 重置密码,设置复杂密码。查看配置文件(不推荐,风险高)。使用系统命令行工具(不推荐,需要对命令行工具精通)。

CENTOS面试问题:ACE您的Linux系统管理员面试 CENTOS面试问题:ACE您的Linux系统管理员面试 Apr 09, 2025 am 12:17 AM

CentOS面试常见问题及解答包括:1.使用yum或dnf命令安装软件包,如sudoyuminstallnginx。2.通过useradd和groupadd命令管理用户和组,如sudouseradd-m-s/bin/bashnewuser。3.使用firewalld配置防火墙,如sudofirewall-cmd--permanent--add-service=http。4.设置自动更新使用yum-cron,如sudoyuminstallyum-cron并配置apply_updates=yes。

navicat如何执行sql navicat如何执行sql Apr 08, 2025 pm 11:42 PM

在 Navicat 中执行 SQL 的步骤:连接到数据库。创建 SQL 编辑器窗口。编写 SQL 查询或脚本。单击“运行”按钮执行查询或脚本。查看结果(如果执行查询的话)。

navicat怎么新建连接mysql navicat怎么新建连接mysql Apr 09, 2025 am 07:21 AM

可在 Navicat 中通过以下步骤新建 MySQL 连接:打开应用程序并选择“新建连接”(Ctrl N)。选择“MySQL”作为连接类型。输入主机名/IP 地址、端口、用户名和密码。(可选)配置高级选项。保存连接并输入连接名称。

Navicat 无法连接 MySQL/MariaDB/PostgreSQL 等数据库的解决方法 Navicat 无法连接 MySQL/MariaDB/PostgreSQL 等数据库的解决方法 Apr 08, 2025 pm 11:00 PM

Navicat 无法连接数据库的常见原因及其解决方法:1. 检查服务器运行状态;2. 核对连接信息;3. 调整防火墙设置;4. 配置远程访问;5. 排除网络问题;6. 检查权限;7. 保障版本兼容性;8. 排除其他可能性。

See all articles