linux中mysql密码忘记了怎么办

linux中mysql密码忘记了怎么办,第1张

1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库。因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的状态下,其他的用户也可以任意地登录和修改MySQL的信息。可以采用将MySQL对外的端口封闭,并且停止Apache以及所有的用户进程的方法实现服务器的准安全状态。最安全的状态是到服务器的Console上面 *** 作,并且拔掉网线。

2.修改MySQL的登录设置:

# vi /etc/my.cnf在[mysqld]的段中加上一句:skip-grant-tables

例如:

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

skip-grant-tables

保存并且退出vi。

3.重新启动mysqld

# /etc/init.d/mysqld restart

Stopping MySQL: [ OK ]

Starting MySQL: [ OK ]

4.登录并修改MySQL的root密码

# /usr/bin/mysql

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

Your MySQL connection id is 3 to server version: 3.23.56

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

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

mysql>UPDATE user SET Password = password ( 'new-password' ) WHERE User = 'root'

Query OK, 0 rows affected (0.00 sec)

Rows matched: 2 Changed: 0 Warnings: 0

mysql>flush privileges

Query OK, 0 rows affected (0.01 sec)

mysql>quit

Bye

5.将MySQL的登录设置修改回来

# vi /etc/my.cnf

将刚才在[mysqld]的段中加上的skip-grant-tables删除

保存并且退出vi。

6.重新启动mysqld

# /etc/init.d/mysqld restart

Stopping MySQL: [ OK ]

Starting MySQL: [ OK ]

linux忘记mysql密码处理方法,下面提供了5种linux忘记mysql密码找回方法哦。

方法一:

# /etc/init.d/mysql stop

# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

# mysql -u root mysql

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

mysql>flush privileges

mysql>quit

# /etc/init.d/mysql restart

# mysql -uroot -p

enter password: <输入新设的密码newpassword>

mysql>

方法二:

直接使用/etc/mysql/debian.cnf文件中[client]节提供的用户名和密码:

# mysql -udebian-sys-maint -p

enter password: <输入[client]节的密码>

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

mysql>flush privileges

mysql>quit

# mysql -uroot -p

enter password: <输入新设的密码newpassword>

mysql>

方法三:

这种方法我没有进行过测试,因为我的root用户默认密码已经被我修改过了,那位有空测试一下,把结果告诉我,谢谢!!

# mysql -uroot -p

enter password: <输入/etc/mysql/debian.cnf文件中[client]节提供的密码>

方法四:

方法如下: 1, 关闭mysql服务 /etc/init.d/mysqld stop 2,使用 –skip-grant-tables选项启动mysql服务,可以修 改/etc/inin.d/mysqld脚本启动位置增加此选项, vi /etc/init.d/mysqld

方法如下:

1, 关闭mysql服务

/etc/init.d/mysqld stop

2,使用 –skip-grant-tables选项启动mysql服务,可以修 改/etc/inin.d/mysqld脚本启动位置增加此选项,

vi /etc/init.d/mysqld

在下面运行启动的语句里增加--skip-grant-tables

/usr/bin/mysqld_safe --skip-grant-tables --datadir="$datadir" --socket="$socketfile"

--log-error="$errlogfile" --pid-file="$mypidfile"

加入--skip-grant-tables的意思是启动mysql服务的时候跳 过权限表认证。启动后,连接到mysql的root不需要口令

3,重新启动mysql服务

/etc/init.d/mysqld start

4. 修改root用户的密码;

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

mysql>flush privileges;

mysql>quit

5. 重新启动mysql,就可以使用 新密码登录了。

mysql

mysql -u root –p

输入密码:123456

6,关闭mysql服务

/etc/init.d/mysqld stop

7, 重新修改第2步修改的/etc/init.d/mysqld,使其保持原来不变,也就是取消--skip-grant-tables语句

8,重新 启动mysql服务

/etc/init.d/mysqld start转载请注明文章来源: http://www.7000tt.com/Html/?5300.html


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/9006233.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-23
下一篇2023-04-23

发表评论

登录后才能评论

评论列表(0条)

    保存