October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk8 min

What Is the Default MySQL Password and How Do You Reset It?

There is no single MySQL default password. This guide explains temporary and passwordless initialization, exact ALTER USER commands, host matching, and safe --skip-grant-tables recovery.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

MySQL has no universal default password. The initial root credential depends on how the data directory was initialized: a normal initialization creates a random, expired temporary password in the server error log, while an insecure initialization creates root without a password. In both cases, set a strong password immediately. If the existing password is forgotten, a controlled --skip-grant-tables recovery can restore access, but it temporarily removes authentication checks.

How MySQL creates the first root credential

The password question is really an initialization question. MySQL stores accounts in its privilege tables, and the command used to create the data directory determines whether the first root@localhost account receives a temporary secret or none at all. Installers can invoke either mode, so two machines running the same MySQL release may begin with different login behavior.

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.

Normal initialization: random temporary password

When the server is initialized with mysqld --initialize, MySQL creates root@localhost with a randomly generated password. That password is temporary and expired; it is intended only to let you establish a permanent credential. MySQL writes the generated value to the server error log. It is not a universal value such as root, mysql, the computer name, or a blank string.

Use the exact random value from the error log with the client prompt:

mysql -u root -p

After the client accepts the temporary credential, MySQL requires a password change before ordinary administrative work. The replacement is made with ALTER USER, shown in the procedure below.

Insecure initialization: no password

When the data directory is initialized with mysqld --initialize-insecure, the initial root account has no password. The supported first login is:

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

This is an initial condition, not a safe operating configuration. Assign a strong password during the first session, then use password authentication for subsequent logins.

Why an installer may appear to have a different default

A package installer or hosting image may initialize the data directory on your behalf, print a generated password in its setup output, or leave you instructions for a local socket login. Those behaviors are installer-specific. Check the installation messages and the MySQL error log rather than trying common guesses. If you did not initialize this data directory yourself, first determine which initialization path was used.

Identify the current state before changing it

Start by recording the server instance you are trying to reach. MySQL account names contain both a user and a host component, so a successful login to one endpoint does not prove that another endpoint uses the same account.

  • Find the data directory and the server error log configured for that instance. The random temporary password from --initialize is recorded there.
  • Note whether the server was initialized with --initialize or --initialize-insecure, if that information is available in installation records.
  • Identify the connection endpoint used by your client: a local socket, localhost, 127.0.0.1, or ::1.
  • Confirm that the client and server belong to the same installation. Multiple MySQL instances can run on one host, each with its own data directory, error log, and accounts.

Do not put the password after -p on the command line. Use -p by itself so the client prompts interactively; an inline value can be exposed through process inspection and shell history.

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

Set a permanent password when the temporary password is available

Use this path when the random value is in the error log and has not been lost.

  1. Open a terminal on the machine running MySQL, or use an administration session that reaches that server.

  2. Start the client and wait for its password prompt:

    mysql -u root -p
  3. Enter the random password exactly as logged. Because the credential is expired, this session is for changing it, not for routine administration.

  4. At the MySQL prompt, replace new_password with a long, unique secret and run:

    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.
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
  5. Exit the client, reconnect with mysql -u root -p, and verify that the new password works.

The account named in the statement is specifically root@localhost. If your installation uses a different host entry, changing that row will not change another root account with a different host part.

Set the first password after an insecure initialization

For a data directory created with --initialize-insecure, log in without supplying a password and immediately create one:

  1. Connect locally:

    mysql -u root --skip-password
  2. Run the account change:

    ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
  3. Exit and test a normal prompted login:

    mysql -u root -p

If the no-password connection fails, the data directory may not have been initialized insecurely, the client may be reaching another instance, or the account may use a different host component. Treat an access-denied response as a diagnostic clue rather than evidence that a standard default password exists.

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

Reset a forgotten password with skip-grant-tables

When no valid administrative credential remains, MySQL documents a recovery mode that bypasses the normal privilege checks. It requires taking the server out of ordinary service temporarily and should be performed by an administrator with local control of the machine.

  1. Stop the MySQL server. Use the service manager or startup method for your operating system. Make sure you are stopping the instance whose data directory contains the account you need to recover.

  2. Start the server temporarily with --skip-grant-tables. Follow the platform-specific startup procedure for your installation. Do not leave this option in a persistent service configuration.

  3. Connect without a password. With privilege-table checks bypassed, invoke the MySQL client without -p:

    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.
    mysql
  4. Reload the account tables, then change the credential. At the SQL prompt, run:

    FLUSH PRIVILEGES;
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
  5. Stop the bypassed server and restart normally. Remove --skip-grant-tables and any temporary skip_networking override before bringing the instance back into service.

  6. Test the recovered account. Use a prompted login and the host endpoint that matches the account you changed.

“This enables anyone to connect without a password and with all privileges.”

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

That warning from the MySQL manual describes the central risk. While --skip-grant-tables is active, authentication checks are disabled. Anyone who can connect to the server can act with full privileges, so keep the recovery window short and restrict local access to trusted administrators.

The bypass also enables skip_networking. Remote TCP connections are therefore disabled during this recovery mode by design. A remote administration tool or application will not be able to connect until you restart the server without the bypass settings.

Understand the account host part

MySQL identifies an account by the pair of values before and after the @. These are separate accounts even when the user name is identical:

Account name What it matches Practical implication
root@localhost A connection resolved as localhost, commonly a local socket or name-based local connection Changing this account does not automatically change root accounts tied to numeric addresses.
[email protected] A local IPv4 connection made explicitly to 127.0.0.1 A client forced to this address may receive “access denied” even after root@localhost was reset.
root@::1 A local IPv6 loopback connection IPv6 loopback tests can select a different privilege row from IPv4 or name-based tests.

If skip_name_resolve is enabled, the server does not resolve host names for account matching. A client connecting to 127.0.0.1 or ::1 may therefore fail to match root@localhost. Either connect through the endpoint represented by the existing account or create and manage an account whose host part matches the address, using an already authorized administrative session.

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

Choose the correct procedure

This matrix helps avoid using the most disruptive recovery method when a normal password change is sufficient.

Situation Initialization or credential state Server outage needed? Action Main security concern
Temporary credential is known --initialize; random password appears in the error log and is expired No Log in with mysql -u root -p, then run ALTER USER Protect the logged password and replace it immediately.
No initial password was created --initialize-insecure No Use mysql -u root --skip-password, then run ALTER USER Do not leave the account passwordless.
Password forgotten Existing credential unavailable Yes Start temporarily with --skip-grant-tables, run FLUSH PRIVILEGES and ALTER USER, then restart normally Authentication is disabled; local users can connect with full privileges.
Login reaches the wrong host row Host part differs, or skip_name_resolve affects matching Usually no Use a matching endpoint or manage the account for the actual host value Changing one root row does not change the others.

Verify the reset without creating a new security problem

  • Close the recovery session and reconnect with -p so the client prompts for the password.
  • Test the same endpoint used by the application or administrator. A successful socket login does not validate an IPv4 or IPv6 connection.
  • Remove every temporary --skip-grant-tables and skip_networking setting before normal service resumes.
  • Store the new secret in an approved password manager or secret store rather than in shell history, scripts, or service files readable by other users.
  • Use a separate least-privilege account for applications; reserve the root account for administration.

MySQL documents mysql_secure_installation as a utility that automates much of the initial hardening process. It is optional and does not supply a universal password. MySQL Workbench also provides a graphical account-management path for administrators who prefer a user interface; it still operates on the same user-and-host accounts and privilege tables.

Common errors and their fixes

“Access denied for user ‘root’” after a successful reset

Check the host endpoint first. The client may be selecting [email protected] or root@::1 while you changed root@localhost. Try the intended local socket or address, and inspect name-resolution settings before changing additional accounts.

The temporary password is rejected

Confirm that you copied the value from the error log for this exact server instance. A second data directory can produce a different password, and an expired temporary password is not interchangeable with a permanent one. If the log is unavailable and no administrative account works, use the controlled recovery procedure rather than guessing.

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

ALTER USER is rejected during recovery

Ensure that you ran FLUSH PRIVILEGES; after connecting with --skip-grant-tables. Also verify that the account specification matches the row you intend to change. Restarting normally and attempting the statement without a valid credential will not solve a forgotten-password situation.

Remote tools cannot connect while resetting

This is expected during --skip-grant-tables recovery because skip_networking disables remote connections. Perform the SQL change locally, then stop and restart the server without the bypass option.

A script exposes the password

Replace commands such as mysql -u root -pSecretValue with mysql -u root -p. Prompted entry avoids placing the secret in the process list and commonly avoids recording it in shell history.

A concise recovery checklist

  1. Find the correct MySQL instance and its error log.
  2. Determine whether initialization was normal or insecure.
  3. If the random password is available, use prompted login and change it with ALTER USER.
  4. If the account was intentionally passwordless, connect with --skip-password once and set a password immediately.
  5. If the password is forgotten, take the server offline, use --skip-grant-tables only for the recovery window, run FLUSH PRIVILEGES followed by ALTER USER, and restart without the bypass.
  6. Check the account host part and test the exact endpoint your client uses.
  7. Keep passwords out of command-line arguments and return applications to least-privilege accounts.

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.

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

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
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.