Article list
Author writing

Linux Server, Reset MySQL Password

I had an idle Tencent Cloud server that was expiring at the end of the year and I hadn’t planned to renew it. So, I decided to deploy a MySQL database for development purposes. When reinstalling the system, I wanted to save time and chose a third-party image provided by Tencent Cloud, which already had MySQL installed. I thought the system should include a Readme file or similar documentation explaining the password and deployment path.

On this page

The Tencent Cloud server reinstalled very quickly, taking about a minute. Once logged in, systemctl status mysql showed that the service was running. I started searching for the password but couldn’t find it anywhere, and I began to panic.

Then, I thought, since I had already accessed the server with root privileges, there must be a way to reset the password. I searched through documentation and found a forum post on Alibaba Cloud’s forum, continuing to tinker.

Reset Password

Edit the configuration file vim /etc/my.cnf, add the following configuration to the mysqld node: skip-grant-tables, and execute the command to restart the database: systemctl restart mysql.

Then, log in directly to the data using mysql, after which everything will proceed normally. To reset the root user password and enable allowing remote login simultaneously:

USE mysql;
UPDATE user SET authentication_string = password('pass') WHERE User = 'root';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'pass' WITH GRANT OPTION;
FLUSH PRIVILEGES;

To revert the modified configuration file, restart the database, and you’re done.

References

Article reading tools
Author tianlong.xiang License Licensed under CC BY-NC-SA 4.0 Last updated on

Comments will load when you scroll here.