Resetting MySQL password on a Linux server

I have an idle Tencent Cloud server that’s expiring at year-end, and I didn’t plan to renew it. I deployed a MySQL database for development purposes. When reinstalling the system, I chose a third-party image from Tencent Cloud for convenience—it already had MySQL installed. I assumed there would be a Readme file or something similar explaining the password and deployment path.

It quickly reinstalled the system on Tencent Cloud, notifying me it was ready in about a minute. Logging in, the service had already started. I searched for the password but couldn’t find it and slowly began to feel defeated.

Having gained access to the server with those privileges, there must be a way to reset the password. I checked the documentation and found a post on the Alibaba Cloud forum; time to keep troubleshooting.

Reset password

Edit configuration file

Reuse the existing user password, while enabling remote login

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;

Reverted the configuration file, restarted the database, all done

References

Licensed under CC BY-NC-SA 4.0
Last updated on May 28, 2025 09:47
A financial IT programmer's tinkering and daily life musings
Built with Hugo
Theme Stack designed by Jimmy