Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What if mysql forgets his password in linux?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the "linux mysql forgot password how to do" related knowledge, Xiaobian through the actual case to show you the operation process, the method of operation is simple and fast, practical, I hope that this "linux mysql forgot password how to do" article can help you solve the problem.

Solutions: 1, use the "service mysql stop" command to shut down the mysql service; 2, modify the mysql configuration file "my.conf"; 3, restart the database with the "service mysqld start" command; 4, use the "use mysql" statement to change the password.

The operating environment of this tutorial: linux7.3 system, mysql8.0.22 version, Dell G3 computer.

How to solve the problem of mysql forgetting password in linux

Solution:

1. Check whether the mysql service is started, and if so, shut down the mysql service

/ / check mysql service status [root@mytestlnx02 ~] # ps-ef | grep-I mysqlroot 22972 10 14:18 pts/0 00:00:00 / bin/sh / usr/bin/mysqld_safe-- datadir=/var/lib/mysql-- socket=/var/lib/mysql/mysql.sock-- pid-file=/var/run/mysqld/mysqld.pid-- basedir=/usr-- user=mysqlmysql 23166 22972 0 14:18 pts/0 00:00:00 / usr/sbin / mysqld-- basedir=/usr-- datadir=/var/lib/mysql-- plugin-dir=/usr/lib/mysql/plugin-- user=mysql-- log-error=/var/log/mysqld.log-- pid-file=/var/run/mysqld/mysqld.pid-- socket=/var/lib/mysql/mysql.sockroot 23237 21825 0 14:22 pts/0 00:00:00 grep-I mysql// shutdown service [root@mytestlnx02 ~] # service mysql stop [root@mytestlnx02 ~] #

two。 Modify the configuration file my.cnf of mysql

The location of the my.cnf configuration file, usually in / etc/my.cnf, and some versions in / etc/mysql/my.cnf

In the configuration file, add 2 lines of code

[mysqld] skip-grant-tables

The function is to skip password verification when logging in to mysql

Then start the mysql service and enter mysql

[root@mytestlnx02 ~] # service mysqld start [root@mytestlnx02 ~] # [root@mytestlnx02 ~] # mysql-u root Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.mysql >

3. Modify the password

Connect to the mysql database and change the user's password

Mysql > use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with-A Database changedmysql > update mysql.user set authentication_string=password ('root_password') where user='root';Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql > flush privileges;Query OK, 0 rows affected (0 sec) mysql > exit

4. Restart the mysql service

Comment or delete the 2 lines of code previously added to the configuration file, then restart the mysql service, and you can log in with the password you just set.

[root@mytestlnx02] # service mysql start [root@mytestlnx02] # [root@mytestlnx02] # mysql-u root-pEnter password: Welcome to the MySQL monitor. Commands end with; or\ g.

It operates differently on CentOS.

The command to change the password has been reported wrong all the time.

Mysql > update user set authentication_string=password ('xxxxxxxx') where User='root'; 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' ('root_password') where User='root'' at line 1

It can't be a syntax problem. I checked it many times and finally found that it should be done like this under CentOS:

View initial password

[root@VM_0_8_centos] # grep 'temporary password' / var/log/mysqld.log2018-09-26T04:25:54.927944Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: DN34N/=?aIfZ

You can see that the initial password is DN34N/=?aIfZ

Log in with the initial password

[root@VM_0_8_centos] # mysql-u root-pEnter password: Welcome to the MySQL monitor. Commands end with; or\ g.Your MySQL connection id is 8Server version: 8.0.12 MySQL Community Server-GPLCopyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Modify the password

Mysql > ALTER USER 'root' IDENTIFIED BY' xxxxxxxxx'; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.mysql > ALTER USER 'root'@'localhost' IDENTIFIED BY' xxxxxxxx';Query OK, 0 rows affected (0.11 sec) mysql > flush privileges;Query OK, 0 rows affected (0.01 sec) mysql > exitBye

Restart the service and take effect.

[root@VM_0_8_centos ~] # service mysqld stop Redirecting to / bin/systemctl stop mysqld.service [root @ VM_0_8_centos ~] # service mysqld startRedirecting to / bin/systemctl start mysqld.service about "how to forget your password in linux". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report