NEW LOCATION

Olá Brazil Brazil NVMe-powered VPS Plans in Brazil Now Available.

Deploy Instantly
  • +357 2425 0808
  • Login
  • English

Home

Blog

How To Reset Forgotten MySQL 5.7 Root Pa...

How To Reset Forgotten MySQL 5.7 Root Pass in Linux

How To Reset Forgotten MySQL 5.7 Root Pass in Linux

NetShop ISP

NetShop ISP · Blog Author

Feb 09, 2024 · Technical Tutorials

Often linux users, and especially server admins, realize they have lost the mysql root pass. When managing databases this is a real issue as without the root password there is no much you can do in terms of database administration.

Whilst there are thousands of articles out there explaining the procedure to recover the password of mysql root user, you may be still facing an issue when trying to replicate the steps from those articles.

Recently, one of our server engineers were called on duty to recover a lost MySQL root password for a client’s CentOS server. In this article we list all necessary steps for a working solution to reset your MySQL root password.

Steps to Recover MySQL Root Account

Step 1: Stop MySQL Server

root@localhost:~$ service mysql stop

Step 2: Start MySQL with skipping grant privileges and networking

The first two commands below are usually omitted from other tutorials, and users are instructed to do only the 3rd command. However, in our case with MySQL 5.7 server we had to do all commands as shown below.

root@localhost:~$ mkdir -p /var/run/mysqld

The command above will create the directory /var/run/mysqld if doesn’t exist; that is the purpose of argument -p.

root@localhost:~$ chown mysql:mysql /var/run/mysqld

Now proceed to starting mysqld with skip-grant-tables and skip-networking arguments.

root@localhost:~$ /usr/sbin/mysqld --skip-grant-tables --skip-networking

Step 3: Password-less login to MySQL as Root

We are now ready to login to mysql as root without the need of a password (we don’t have it anyway!).

root@localhost:~$ mysql -u root

At this point you will see the mysql shell, so continue with the following commands to reset your mysql root password.

Step 4: Flush Privileges & Set New Password

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected, 3 warnings (0.02 sec)

Now let’s set a new root password as follows:

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('TypeSomethingStrongHere@#45');
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> quit
Bye

Step 5: Restart MySQL Server

Dtop the current mysql process with the following command:

root@localhost:~$ kill %1

Sample Output:

[1]+  Done                    /usr/sbin/mysqld --skip-grant-tables --skip-networking

Start MySQL server normally:

root@localhost:~$ service mysql start

You are good to go! You should be able to access MySQL using your new root password as you set it in Step 4. Congratulations!

Press Releases
79

Free VPS Trial

No Credit Card Required.

Recent Posts

Black Friday & Cyber Monday Offer – 30% Lifetime Discount on VPS Plans

Black Friday & Cyber Monday Offer – 30% Lifetime Discount on VPS Plans

02 December, 2024

How To Install Sendy on Ubuntu 22.04 Server

How To Install Sendy on Ubuntu 22.04 Server

27 November, 2024

How To Extract Certificates and Private Key from .PFX file

How To Extract Certificates and Private Key from .PFX file

19 November, 2024

NetShop ISP CEO Stefano Sordini to Moderate Key Panel on Forex AI Automation at Cyprus Fintech Summit 2024

NetShop ISP CEO Stefano Sordini to Moderate Key Panel on Forex AI Automation at Cyprus Fintech Summit 2024

15 November, 2024

Preparing for the Daylight Saving Time (DST) Change: Essential Updates for MetaTrader 4/5 Platforms

Preparing for the Daylight Saving Time (DST) Change: Essential Updates for MetaTrader 4/5 Platforms

25 October, 2024

#letushostyou

Award Winning Hosting Provider established in 2004.

120 Faneromenis Avenue, Imperial Tower, 2nd Floor, Larnaca 6031, Cyprus

Products

Bare Metal Servers

Customized Servers

Virtual / Cloud Servers

Forex VPS

Storage VPS

cPanel Web Hosting

Reseller Web Hosting

Colocation

Addons

Premium DNS

Email Hosting

Cloud Backup

DDoS Protection

Licenses

SSL Certificates

Domain Names

Premium SLAs

About Us

Data Center Locations

Looking Glass

Our Company

Contact Us

Careers in Cyprus

Become a Partner

Awards

Certifications

© 2024 S.S. NetShop Internet Services Ltd. All rights reserved.  Terms & Conditions  |  Privacy Policy
CY Reg. Number: HE 217340 | EU VAT Number: CY10217340J

Visa
Mastercard
PayPal
Bitcoin
Tether
Ethereum
Litecoin
Wise
Revolut
Wire Transfer