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

How to solve the problem that mysql forgot to change the password on linux

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

I would like to share with you how to solve the problem that I forgot to change the mysql password on linux. I believe most people don't know much about it, so share this article for your reference. I hope you will get a lot after reading this article. Let's learn about it together.

Solution: 1, in my.cnf, add "[mysqld]" and "skip-grant-tables" two lines of code to skip password verification when logging in; 2, start mysql service, log in to mysql;3, connect to mysql database, and use the UPDATE command to change the user's password.

The solution of forgetting the password changed by mysql on linux

Modify the password

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.

P.s.

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 is all about how to solve the problem of mysql changing password on linux. Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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

Database

Wechat

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

12
Report