DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk9 min

How to Restore MySQL Root Access Privileges on a Linux Server

A practical Linux recovery guide for MySQL root access, covering Ubuntu socket authentication, ALTER USER, forgotten-password recovery with skip-grant-tables, plugin compatibility, host-qualified accounts, and post-restart verification.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A failed mysql -u root -p login does not necessarily mean that MySQL’s root account has lost its privileges. On many Ubuntu installations, root@localhost is configured with the auth_socket plugin, so the operating-system root user connects through the local Unix socket with sudo mysql -u root and no MySQL password. If that path is unavailable and the password is forgotten, you can recover access with a short, isolated --skip-grant-tables startup, reload the privilege tables, change the account with ALTER USER, and restart MySQL normally.

The safe order is: identify the connection that is failing, inspect the exact User/Host account row, use the least disruptive recovery path, and verify that emergency options are gone before returning the server to service.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the recovery path before changing anything

Write down the exact command, complete error text, MySQL version, Linux distribution, and whether the client is using a Unix socket or TCP. Those details determine which account row MySQL evaluates. A password for root@localhost is not automatically a password for [email protected] or another host-qualified row.

What you know Best next step Restart required?
sudo mysql -u root opens a prompt Inspect the plugin and grants. Keep socket authentication, or deliberately switch with ALTER USER. No
The current MySQL password is known, but login fails Check the socket/TCP path and the account’s Host value, then use ALTER USER if a password change is needed. No
The password is forgotten and socket login is unavailable Use a maintenance window and an isolated --skip-grant-tables --skip-networking startup. Yes
A client requires an older authentication plugin Use caching_sha2_password by default; select mysql_native_password only for that compatibility requirement. Usually no

Do not edit mysql.user directly as a first resort. The table is part of MySQL’s data dictionary, and its columns and update behavior vary by version. Account statements such as ALTER USER are the supported interface.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

Why sudo mysql works when a password login fails

Ubuntu’s packaged MySQL configuration commonly creates 'root'@'localhost' with the auth_socket authentication plugin. The plugin checks the operating-system identity presented on the local Unix socket rather than asking for a MySQL password. Consequently, an operating-system root session can enter with:

sudo mysql -u root

By contrast, this command asks for password authentication:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
mysql -u root -p

If the account is using auth_socket, a password prompt can fail even though the account still has full administrative privileges. A successful sudo mysql -u root test means you probably do not need a password reset; you need to decide whether socket-only administration is suitable for your workflow.

Inspect the account that actually authenticated

At the mysql> prompt, run:

SELECT User, Host, plugin FROM mysql.user WHERE User = 'root';
SHOW GRANTS FOR 'root'@'localhost';

The first query may return several root rows. The Host column is part of the account identity, not a comment. The second query confirms the privileges on the local row, but only use it when that row exists; substitute the exact host value returned by the first query when necessary.

Keep the distinction between these two identity functions in mind during troubleshooting:

SELECT CURRENT_USER(), USER();
  • CURRENT_USER() shows the MySQL account row used for privilege checking, including its host part.
  • USER() shows the username and host supplied by the client.

If they differ, MySQL matched the connection to a different account row than the one you expected. That often explains why changing one root row did not fix a connection made over another path.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When you can log in: set or replace root authentication safely

If you have an administrative session through sudo mysql, use ALTER USER rather than editing grant tables. Replace the example secret with a long, unique value that is not used elsewhere.

Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.

Give root@localhost a password

ALTER USER 'root'@'localhost'
  IDENTIFIED BY 'A-long-unique-secret';

This changes the authentication method to password authentication using the server’s current default password plugin. On current MySQL releases that default is generally caching_sha2_password, the modern choice documented by MySQL.

Keep socket authentication instead

If local, operating-system-controlled administration is intentional, leave the plugin unchanged and continue using:

sudo mysql -u root

This avoids storing or distributing a root database password, but it does not provide password-based root access for scripts, remote clients, or users who cannot become operating-system root. Use a separate, narrowly privileged account for applications and routine administration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the legacy plugin only for a proven client limitation

A connector that cannot negotiate caching_sha2_password may require the compatibility plugin:

ALTER USER 'root'@'localhost'
  IDENTIFIED WITH mysql_native_password BY 'A-long-unique-secret';

Do not select mysql_native_password merely because it appears in an older tutorial. First confirm that the specific client or library cannot use caching_sha2_password; otherwise, retain the modern plugin and upgrade the client when practical.

Target every host-qualified row deliberately

If the account query shows [email protected], root@::1, or another host value, alter that exact row:

ALTER USER 'root'@'127.0.0.1'
  IDENTIFIED BY 'A-long-unique-secret';

Do not assume that changing root@localhost changes a different row. Also avoid creating broad wildcard root accounts simply to make a login succeed; a wildcard can grant administrative access from more connection sources than intended.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by

Forgotten password: controlled recovery with --skip-grant-tables

Use this procedure only when normal administrative access is unavailable. It requires a maintenance window, local console or equivalent privileged access, and a plan to keep the server isolated while authentication is disabled. In this mode, MySQL permits passwordless connections with all privileges. Account-management statements such as ALTER USER are disabled until you execute FLUSH PRIVILEGES.

Prepare the maintenance window

  • Tell application owners that the database will be stopped and restarted.
  • Ensure you can log in to the Linux host as an operating-system administrator.
  • Prevent remote access during recovery. The example below uses --skip-networking.
  • Have the exact root host row ready from previous account information, if it is known.
  • Use a temporary secret and transfer it through a protected channel; do not put it in shell history or a public script.

Stop the normal service

On systems managed by systemd, the service is commonly named mysql:

sudo systemctl stop mysql

Some distributions use a different unit name or service manager. Confirm the local distribution’s documented service command rather than substituting a guessed name. Verify that the normal server process has stopped before starting the maintenance instance.

Start an isolated maintenance instance

sudo mysqld_safe --skip-grant-tables --skip-networking --user=mysql &

--skip-grant-tables bypasses password checks and grants every connected session full privileges. --skip-networking prevents TCP connections while the bypass is active. --user=mysql keeps the server process running as the database operating-system user; starting the daemon as Unix root can create root-owned files in the data directory and cause later startup failures. On installations without mysqld_safe, use the distribution’s documented maintenance-start mechanism while preserving the same three properties: no remote networking, the correct database user, and a temporary lifetime.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Connect without a password and reload the privilege system

mysql -u root

At the SQL prompt, re-enable account statements and set the password:

FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'A-long-unique-secret';
EXIT;

If the account query from an earlier session identified a different host part, replace 'localhost' with that exact value. Do not skip FLUSH PRIVILEGES; until the privilege tables are reloaded, MySQL intentionally rejects statements that manage accounts.

End the bypass and restart normally

Stop the temporary maintenance process, then start the service through the normal service manager:

Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.
sudo systemctl stop mysql
sudo systemctl start mysql

The first command stops the service when the temporary process is registered with the service manager. If mysqld_safe was launched independently and remains in the background, terminate that temporary instance using the process-control method documented for your distribution before starting the normal service. Never leave a --skip-grant-tables process running after the password has been changed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Verify the restored access and remove emergency settings

After the ordinary service is running, test the intended authentication path rather than assuming the restart succeeded.

Test password authentication

mysql -u root -p

Enter the new secret when prompted. If this fails, do not immediately repeat the reset. Check whether the client is using a socket or TCP, then compare its destination with the Host values returned by the account query. For example, a client forced to 127.0.0.1 can match a different row from one using the default socket.

Confirm the effective account and grants

SELECT CURRENT_USER(), USER();
SHOW GRANTS;

These results show which account row supplied the privileges and what that session can do. If you changed a row but the effective account is different, correct the exact row rather than broadening privileges indiscriminately.

Check configuration and process arguments

  • Search the MySQL configuration files and service overrides for an unintended skip-grant-tables setting.
  • Remove any temporary skip-networking setting unless it is part of the server’s deliberate permanent design.
  • Inspect the running process arguments or service definition to ensure the normal daemon, not the emergency instance, is active.
  • Review ownership of the data directory and recent files. They should be owned according to the distribution’s MySQL service account, not Unix root.

Only after these checks should applications be allowed to reconnect. Test the access path they actually require, and do not expose a root account remotely just to avoid correcting an application’s credentials.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common failure modes and precise fixes

“Access denied” from mysql -u root -p, but sudo mysql works

This usually indicates socket authentication, not missing privileges. Query the plugin, then either continue with sudo mysql -u root or deliberately assign a password with ALTER USER. Repeatedly guessing passwords will not convert auth_socket into password authentication.

The password was changed, but the application still fails

Check the application’s destination and transport. A socket connection, localhost, 127.0.0.1, an IPv6 loopback address, and a remote hostname can select different account rows. Compare CURRENT_USER() in a test session with the row you altered, then change only the required row.

ALTER USER is rejected during recovery

That is expected before FLUSH PRIVILEGES in --skip-grant-tables mode. Run the reload statement first, then issue ALTER USER. If the statement still fails, confirm that you are connected to the maintenance instance and that no second normal server is receiving the command.

The server will not start after recovery

Look for a still-running maintenance process, a stale socket or PID file, root-owned files created by an incorrectly launched daemon, and configuration files that still contain emergency options. Stop all unintended MySQL processes, restore ownership to the distribution’s MySQL user, remove temporary options, and start through the normal service manager. Use the distribution’s logs to identify the exact startup error instead of deleting data-directory files blindly.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

mysql_native_password appears in an old guide

It remains a compatibility option, not the default recommendation. Use it only when a specific legacy connector cannot work with caching_sha2_password. Record that exception so it can be revisited when the connector is upgraded.

mysql_secure_installation did not solve the problem

The utility provides hardening prompts and can help set a password in some installations, but running it does not prove that the root account changed from auth_socket. Inspect User, Host, and plugin, then use the explicit ALTER USER statement for the account and authentication method you actually want.

After access is restored: reduce the chance of another lockout

Create a separate administrative account

Use root for recovery and server-level changes, not for every script or routine task. Create an individual administrator with only the privileges required for its job, grant them explicitly, and retain a documented recovery path. Applications should use separate accounts with permissions limited to their own schemas and operations.

Document the chosen authentication path

Record whether local administration uses auth_socket or a password, which host-qualified account rows exist, and which clients require TCP, Unix sockets, or a legacy plugin. This prevents a future operator from “fixing” a working socket-authenticated account by repeatedly resetting an irrelevant password.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Protect the new credential

  • Use a unique secret and store it in an approved secret-management system.
  • Do not place the password directly in shell commands, screenshots, tickets, or world-readable configuration files.
  • Restrict remote administrative access with network controls and host-specific MySQL accounts.
  • Review grants periodically and remove accounts or privileges that are no longer needed.

Keep a tested recovery procedure

A recovery runbook should include the service name, data-directory location, operating-system MySQL user, console access method, backup and restore contacts, and the exact post-recovery checks. Test the runbook during a planned maintenance window, not for the first time during an outage.

Quick command checklist

  1. Record the failing command, error, version, distribution, and socket/TCP path.
  2. Try sudo mysql -u root on Ubuntu systems where socket authentication may be configured.
  3. Inspect SELECT User, Host, plugin FROM mysql.user WHERE User = 'root'; and the relevant grants.
  4. If access works, use ALTER USER with the exact User/Host pair.
  5. If the password is forgotten and socket access is unavailable, stop MySQL and start an isolated maintenance instance with --skip-grant-tables --skip-networking --user=mysql.
  6. Connect locally, run FLUSH PRIVILEGES, then run ALTER USER.
  7. Stop the temporary instance and start MySQL normally.
  8. Test the intended login, inspect CURRENT_USER() and SHOW GRANTS, and remove every emergency startup option.
  9. Create least-privilege accounts for routine users and applications.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.