{"id":1617,"date":"2026-09-03T16:59:33","date_gmt":"2026-09-03T11:29:33","guid":{"rendered":"https:\/\/cpanelfree.com\/blog\/how-to-reset-mysql-root-password-linux-vps\/"},"modified":"2026-09-03T17:02:47","modified_gmt":"2026-09-03T11:32:47","slug":"how-to-reset-mysql-root-password-linux-vps","status":"publish","type":"post","link":"https:\/\/cpanelfree.com\/blog\/how-to-reset-mysql-root-password-linux-vps\/","title":{"rendered":"How to Reset MySQL Root Password on Linux VPS (Ubuntu \/ Debian \/ AlmaLinux)"},"content":{"rendered":"<div style=\"background-color: #f8fafc;border-left: 4px solid #a855f7;padding: 20px;border-radius: 6px;margin-bottom: 25px\">\n<p style=\"margin: 0;font-size: 16px;color: #1e293b\">\n        <strong>Quick Answer:<\/strong> To reset a lost MySQL\/MariaDB root password on a Linux VPS: <strong>1)<\/strong> Stop MySQL (<code>sudo systemctl stop mariadb<\/code>), <strong>2)<\/strong> Start MySQL in safe mode with networking disabled (<code>sudo mysqld_safe --skip-grant-tables --skip-networking &amp;<\/code>), <strong>3)<\/strong> Connect without password (<code>mysql -u root<\/code>), <strong>4)<\/strong> Run <code>FLUSH PRIVILEGES;<\/code> and <code>ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword123!';<\/code>, and <strong>5)<\/strong> Kill safe mode and restart the normal MySQL service.\n    <\/p>\n<\/div>\n<h2>Why Root Password Lockouts Happen on Linux VPS<\/h2>\n<p>Losing the MySQL root administrative password blocks all database provisioning, phpMyAdmin root logins, and WP-CLI administration. Fortunately, Linux allows system administrators with root SSH access to bypass the user privilege table safely and assign a new administrative credential.<\/p>\n<h2>Step-by-Step Root Password Reset Procedure<\/h2>\n<h3>Step 1: Stop the Running MySQL Daemon<\/h3>\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\">sudo systemctl stop mariadb  # or sudo systemctl stop mysql<\/pre>\n<h3>Step 2: Start MySQL in Safe Mode (Bypass Permissions)<\/h3>\n<p>Use the <code>--skip-networking<\/code> flag to ensure external hackers cannot connect while authentication is disabled:<\/p>\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\">sudo mysqld_safe --skip-grant-tables --skip-networking &amp;<\/pre>\n<h3>Step 3: Connect to MySQL Shell Without Password<\/h3>\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\">mysql -u root<\/pre>\n<h3>Step 4: Reload Privileges and Update Root Password<\/h3>\n<p>Inside the MySQL\/MariaDB command prompt, execute the following SQL commands:<\/p>\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\">FLUSH PRIVILEGES;\n\n-- For MySQL 8.0 \/ 8.4:\nALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YourNewStrongPassword123!';\n\n-- For MariaDB 10.4+:\nALTER USER 'root'@'localhost' IDENTIFIED VIA mysql_native_password USING PASSWORD('YourNewStrongPassword123!');\n\nFLUSH PRIVILEGES;\nEXIT;<\/pre>\n<h3>Step 5: Terminate Safe Mode and Restart Normal Service<\/h3>\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\"># Kill safe mode daemon\nsudo killall -v mysqld\n\n# Start standard database service\nsudo systemctl start mariadb  # or sudo systemctl start mysql\n\n# Test login with new password\nmysql -u root -p<\/pre>\n<div style=\"background-color: #f8fafc;border: 1px solid #e2e8f0;border-left: 4px solid #0ea5e9;padding: 20px;border-radius: 8px;margin: 30px 0\">\n<h3 style=\"margin-top: 0;color: #0f172a;font-size: 18px;display: flex;align-items: center\">\n        <span style=\"margin-right: 8px\">\ud83d\udd17<\/span> Recommended Related Technical Guides:<br \/>\n    <\/h3>\n<ul style=\"margin: 10px 0 0 0;padding-left: 20px;line-height: 1.8\">\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/how-to-create-mysql-database-user-cpanel\/\" style=\"color: #0284c7;text-decoration: none;font-weight: 600\">How to Create MySQL Database &amp; User with Full Privileges<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/how-to-optimize-mariadb-mysql-configuration-vps\/\" style=\"color: #0284c7;text-decoration: none;font-weight: 600\">How to Optimize MariaDB \/ MySQL Configuration for VPS<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/how-to-fix-error-establishing-database-connection-wordpress\/\" style=\"color: #0284c7;text-decoration: none;font-weight: 600\">How to Fix Error Establishing a Database Connection in WordPress<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/#plans\" style=\"color: #0284c7;text-decoration: none;font-weight: 600\">Explore $0 Free cPanel Web Hosting Plans<\/a><\/li>\n<\/ul>\n<\/div>\n<h2>Fixing Authentication Plugin Mismatches (auth_socket vs mysql_native_password)<\/h2>\n<p>Modern Ubuntu installations default the MySQL root user authentication method to <code>auth_socket<\/code>, allowing the Linux <code>root<\/code> user to log in without a password via local UNIX sockets while rejecting TCP\/phpMyAdmin password logins. To enable dual password authentication:<\/p>\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\"># Configure MySQL 8.0 password authentication\nALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'StrongPassword123!';\n\n# Create dedicated administrative superuser for phpMyAdmin\nCREATE USER 'dba_admin'@'localhost' IDENTIFIED BY 'StrongPassword123!';\nGRANT ALL PRIVILEGES ON *.* TO 'dba_admin'@'localhost' WITH GRANT OPTION;\nFLUSH PRIVILEGES;<\/pre>\n<h2>Securing MySQL Daemon with mysql_secure_installation<\/h2>\n<p>After restoring administrative access, run the native hardening utility to remove anonymous accounts and disable remote root logins:<\/p>\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\">sudo mysql_secure_installation<\/pre>\n<h2>Resetting MySQL Root Password on cPanel &amp; WHM Servers<\/h2>\n<p>If you manage a cPanel &amp; WHM dedicated server or VPS, you can reset the MySQL root password directly from the WHM interface without stopping the daemon:<\/p>\n<ol style=\"padding-left: 20px;line-height: 1.8\">\n<li>Log in to <strong>WHM (WebHost Manager)<\/strong> as root.<\/li>\n<li>In the left search bar, type <strong>MySQL Root Password<\/strong> (under the <em>SQL Services<\/em> section).<\/li>\n<li>Enter your new password and click <strong>Change Password<\/strong>. WHM automatically updates the internal password and synchronizes service credentials across cPanel.<\/li>\n<\/ol>\n<h2>Configuring ~\/.my.cnf for Passwordless Root CLI Administration<\/h2>\n<p>Create a secure local configuration file in your root home directory (<code>\/root\/.my.cnf<\/code>) so you can run administrative commands without typing passwords in shell history:<\/p>\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\">[client]\nuser = root\npassword = YourSecurePassword123!<\/pre>\n<p>Secure the file: <code>chmod 600 \/root\/.my.cnf<\/code>. Now, typing <code>mysql<\/code> connects instantly and securely.<\/p>\n<div style=\"background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);border: 1px solid #334155;border-radius: 12px;padding: 25px;margin: 30px 0;text-align: center\">\n<h3 style=\"color: #38bdf8;margin-top: 0;font-size: 20px\">Effortless Database Management on CpanelFree<\/h3>\n<p style=\"color: #94a3b8;font-size: 14px;line-height: 1.6;max-width: 600px;margin: 0 auto 15px\">\n        Never worry about lost database root credentials. <strong>CpanelFree<\/strong> provides graphical user password management, phpMyAdmin, and 1-click database tools at $0 forever.\n    <\/p>\n<p>    <a href=\"https:\/\/cpanelfree.com\/#plans\" style=\"display: inline-block;background-color: #a855f7;color: #ffffff;padding: 10px 22px;border-radius: 6px;text-decoration: none;font-weight: bold;font-size: 14px\">Claim Free Web Hosting<\/a>\n<\/div>\n<h2>Frequently Asked Questions<\/h2>\n<div style=\"border-bottom: 1px solid #e2e8f0;padding: 12px 0\">\n<h4 style=\"margin: 0 0 8px 0;color: #1e293b\">Why is &#8211;skip-networking critical when using skip-grant-tables?<\/h4>\n<p style=\"margin: 0;color: #475569;font-size: 14px\">When MySQL runs with <code>--skip-grant-tables<\/code>, authentication is completely bypassed. If port 3306 is exposed to the internet without <code>--skip-networking<\/code>, any remote user could connect and alter your databases without credentials.<\/p>\n<\/div>\n<h2>Troubleshooting Access Denied for User &#8216;root&#8217;@&#8217;localhost&#8217;<\/h2>\n<p>If you receive <code>Access denied for user 'root'@'localhost' (using password: YES)<\/code> after resetting your password, verify that the user record in the <code>mysql.user<\/code> table has <code>plugin = 'mysql_native_password'<\/code> or <code>caching_sha2_password<\/code> rather than <code>auth_socket<\/code>.<\/p>\n<div style=\"border-bottom: 1px solid #e2e8f0;padding: 12px 0\">\n<h4 style=\"margin: 0 0 8px 0;color: #1e293b\">Can I reset passwords on live production servers without stopping the daemon?<\/h4>\n<p style=\"margin: 0;color: #475569;font-size: 14px\">If you have root SSH access and sudo privileges, you can log in directly via UNIX socket (<code>sudo mysql<\/code>) and execute <code>ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpass';<\/code> without stopping MySQL.<\/p>\n<\/div>\n<div style=\"background-color: #f1f5f9;padding: 15px;border-radius: 8px;margin: 20px 0\">\n<h4 style=\"margin-top: 0;color: #1e293b\">Pro Sysadmin Tip: Verifying User Host Privileges in mysql.user<\/h4>\n<p style=\"margin: 0;color: #475569;font-size: 14px\">Always inspect the active user table via <code>SELECT user, host, plugin FROM mysql.user;<\/code> to verify that root access is restricted strictly to <code>localhost<\/code> and <code>127.0.0.1<\/code>.<\/p>\n<\/div>\n<p>Following this emergency password reset procedure ensures that administrators can regain full database access safely without corrupting production tables or risking unauthorized access.<\/p>\n<p>Remember to test SSH key authentication and keep root administrative credentials backed up securely in a password vault to prevent future lockout scenarios on Linux cloud instances.<\/p>\n<p>Maintaining isolated administrative accounts with dedicated SSH key authentication guarantees both emergency recovery capabilities and robust server security for production web applications.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Quick Answer: To reset a lost MySQL\/MariaDB root password on a Linux VPS: 1) Stop MySQL (sudo systemctl stop mariadb), 2) Start MySQL in safe mode with networking disabled (sudo mysqld_safe &#8211;skip-grant-tables &#8211;skip-networking &amp;), 3) Connect without password (mysql -u root), 4) Run FLUSH PRIVILEGES; and ALTER USER &#8216;root&#8217;@&#8217;localhost&#8217; IDENTIFIED BY &#8216;NewPassword123!&#8217;;, and 5) Kill [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1616,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[],"class_list":["post-1617","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/1617","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/comments?post=1617"}],"version-history":[{"count":6,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/1617\/revisions"}],"predecessor-version":[{"id":1663,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/1617\/revisions\/1663"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/media\/1616"}],"wp:attachment":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/media?parent=1617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/categories?post=1617"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/tags?post=1617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}