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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

On Ubuntu, the packaged MySQL server commonly creates root@localhost with the auth_socket plugin, so the first administrative login is usually sudo mysql -u root, not mysql -u root -p. To require a password, inspect the account, then explicitly change both its password and authentication plugin with ALTER USER. Test the same connection method your application will use.

The shortest safe procedure

You need operating-system sudo access and a local MySQL administration session. The commands below apply to MySQL installed from Ubuntu packages; MariaDB uses different defaults and can support different authentication-plugin names.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Open the local administrative client:
    sudo mysql -u root
  2. Inspect every root account row:
    SELECT user, host, plugin FROM mysql.user WHERE user = 'root';
  3. If the row is root@localhost and you want password authentication, change the password and plugin explicitly:
    ALTER USER 'root'@'localhost'
      IDENTIFIED WITH caching_sha2_password BY 'NEW_STRONG_PASSWORD';
  4. Leave MySQL and test the password prompt:
    EXIT;
    mysql -u root -p

Replace NEW_STRONG_PASSWORD only in your private administrative session. Use a long, unique secret and do not place a real password in shell history, scripts, tickets, or published documentation.

Why mysql -u root -p often fails on Ubuntu

Ubuntu’s packaged MySQL commonly configures the initial local root account with auth_socket. This plugin authenticates a local Unix-socket client through the operating-system account instead of asking MySQL for a password. Consequently, a user with sudo rights can normally enter MySQL with:

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application:Upgraded attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Warranty & Support: Our Electric air duster comes with 5 years warranty and 24/7 customer service. During this period, if you have any questions,pls kindly feel free to contact us.
sudo mysql -u root

The command’s success does not mean that a MySQL root password exists or that password authentication is enabled. It means the local socket authentication policy accepted the operating-system credentials presented through sudo.

The username and host together identify a MySQL account. root@localhost, root@127.0.0.1, and a root account with another host value are separate rows and can have different plugins and passwords. A password change aimed at the wrong host row either fails or leaves the account you are actually trying to use unchanged.

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.

Password assignment and plugin selection are related but distinct decisions. The MySQL ALTER USER statement is the supported way to assign or change an existing account password. A root account that still uses auth_socket can continue to reject password-based logins even after a password value has been assigned, because the plugin determines how the client is authenticated. Explicitly selecting a password plugin avoids that ambiguity.

Ubuntu’s current server documentation describes the socket-based initial login as the expected first attempt. This is a package default, not a guarantee for every Ubuntu release, manually configured server, container image, or MariaDB installation, so inspect the actual account before changing it.

Inspect the installed server and root account first

Confirm which server is running

Before applying MySQL-specific syntax, check the client and server identity. From a shell, the client reports its package and client version:

mysql --version

After entering the server through sudo, ask the server for its version:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth
SELECT VERSION();

The server banner matters when a tutorial names an authentication plugin. Plugin availability and defaults vary by release. Ubuntu Noble’s manpage for the packaged hardening utility identifies the package as mysql-server-core-8.0, version 8.0.46-0ubuntu0.24.04.4; another Ubuntu release or a vendor repository may ship a different build.

Read all root rows

Run this query from the mysql> prompt:

SELECT user, host, plugin FROM mysql.user WHERE user = 'root';

Typical output on a fresh Ubuntu package includes a row such as root | localhost | auth_socket. Do not assume that result without checking. If several rows appear, decide which one your intended client will match. A local socket connection normally uses the localhost account, while a TCP connection can match a different host row.

Record the exact target

Write down the host value exactly as MySQL displays it. The account in the change statement must use the same combination of user and host. For example, changing root@localhost does not change an independently configured root@127.0.0.1 account. Avoid broad changes to every root row unless you have a documented reason and understand how each row is used.

Switch root@localhost to password authentication

Use an explicit supported plugin

For a current MySQL 8 installation, the following statement both selects the password plugin and assigns the new password:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ALTER USER 'root'@'localhost'
  IDENTIFIED WITH caching_sha2_password BY 'NEW_STRONG_PASSWORD';

caching_sha2_password is the modern password plugin used by current MySQL 8 releases. Plugin support is version-dependent, so do not copy an old tutorial’s plugin name blindly. In particular, older instructions that force mysql_native_password should not be treated as a universal solution; first verify that the installed server supports the requested plugin and that your clients can use it.

The host portion is not optional in this situation. If your inspection query showed a different host, substitute that exact host after confirming that changing it is appropriate. If no expected row exists, stop and determine how the account was created rather than guessing a new host value.

Understand what the statement changes

The ALTER USER statement targets an existing account. Its IDENTIFIED WITH ... BY ... clause makes the authentication method explicit and stores the password for that method. This is different from merely knowing that a password string was entered somewhere: clients must negotiate the selected plugin, and the account row they reach must be the row you changed.

Rank #3
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.

If you are changing the password of an account that already uses a password plugin, MySQL’s documented ALTER USER ... IDENTIFIED BY ... form is the relevant password-changing operation. For Ubuntu’s socket-authenticated root account, specifying WITH caching_sha2_password makes the required plugin switch clear and testable.

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

Keep the secret out of shell commands

Enter the SQL at the protected MySQL prompt instead of putting credentials in a command-line argument. A shell command containing a password can be recorded in history or exposed to other process-inspection tools. The placeholder in the example is deliberately not a usable password; replace it privately with a unique secret that is not reused for an operating-system account, application, or another database.

Verify the new login before closing your administrative path

Exit and test the command users will run

After a successful ALTER USER, leave the current session:

EXIT;

Then test the local password flow:

mysql -u root -p

At the prompt, enter the new password. A successful login confirms that the client reached a matching root account and that the selected password plugin accepted the credentials. Re-run the account query after reconnecting if you need to confirm the stored plugin:

SELECT user, host, plugin FROM mysql.user WHERE user = 'root';

Test the application’s connection mode, not just the shell

An application may use a socket, a TCP address, a connection pool, or a different host name. Because MySQL accounts include a host component, a successful local command does not prove that an application using another connection mode will match the same row. Test with the same host, port, user, and authentication capabilities that the application will use, but do not grant the application remote root access merely to make a test pass.

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

If the client library is old, it may not support the server’s selected password plugin. In that case, upgrade or reconfigure the client according to its vendor documentation rather than weakening the server account by copying an obsolete plugin recommendation. The server version and client version should both be recorded when diagnosing a compatibility problem.

Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.

Keep a recovery route until testing is complete

Do not close your only sudo-capable terminal until the password login has been tested. If the account remains on auth_socket, sudo access is the normal local recovery route. If you deliberately changed the plugin and then lose the password, recovery becomes a server-administration task governed by the installed version and deployment method; plan console or administrator access before making the change.

When keeping auth_socket is the better choice

You do not have to create a MySQL root password. For a server administered only by trusted local operators, retaining socket authentication limits root logins to local Unix-socket clients whose operating-system credentials can obtain sudo access:

sudo mysql -u root

MySQL’s security guidance describes auth_socket as a local authentication method that does not require a password. This can reduce exposure to password guessing and avoids placing a database root secret in local configuration. The trade-off is operational: sudo access is required, and software that expects to send a MySQL password cannot use this root account without a plugin change.

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.

Choose socket authentication when root is strictly for local administration and your automation can execute through an approved privileged operating-system account. Choose password authentication when a supported client genuinely needs a MySQL password and you can protect, rotate, and test that secret. In either case, keep application access separate from root and grant only the privileges the application requires.

Optional hardening with mysql_secure_installation

Ubuntu also provides an interactive hardening utility:

sudo mysql_secure_installation

It is optional; it is not required for the manual ALTER USER procedure. The Ubuntu Noble manpage for the packaged utility reports that it can:

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.
  • Set a password for root accounts.
  • Remove root accounts that are accessible from outside the local host.
  • Remove anonymous users.
  • Remove the test database.

Review every prompt against the server’s real use case. A development machine, a production database, and a host that intentionally provides a test database may need different answers. Removing externally accessible root accounts is generally consistent with keeping root local, but verify that no documented administrative workflow depends on one before confirming the removal.

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

The utility is a hardening workflow, not a substitute for identifying the account row and testing the connection mode. If you run it after a manual password change, read each prompt rather than assuming it will preserve every choice you made earlier. The utility’s package version and behavior can change with the Ubuntu release.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose an authentication method deliberately

Decision factor auth_socket Password authentication
How local root logs in sudo mysql -u root through the Unix socket; no MySQL password is required. mysql -u root -p supplies a MySQL password to the selected password plugin.
Primary security boundary Operating-system identity and sudo policy restrict local access. The password protects the MySQL account; its storage, rotation, and client handling become responsibilities.
Application compatibility Clients that only know password authentication cannot use this root account. Clients must support the selected plugin and reach the matching user-and-host row.
Operational recovery Sudo access is the normal local administration route. Password recovery depends on administrator access and the server version if the secret is lost.
Best fit Local-only administration on a host with controlled sudo access. A verified administrative client or workflow that specifically requires a MySQL password.

Neither option makes remote root access a good application design. Keep the root account local and create a separate least-privilege account for each application or service. This limits the damage from a leaked application credential and prevents routine software from holding unrestricted database privileges.

Troubleshoot common failures

Access denied from mysql -u root -p

The most common Ubuntu explanation is that the account still uses auth_socket. Use the administrative path that matches that plugin:

sudo mysql -u root

Then inspect the plugin:

SELECT user, host, plugin FROM mysql.user WHERE user = 'root';

If the intended row is still auth_socket, either continue using sudo for local administration or explicitly switch that row to a supported password plugin with ALTER USER. A password entered at a prompt cannot override a plugin that does not perform password authentication.

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

ALTER USER reports that the account does not exist

Check the host value in the account query. MySQL identifies an account by both name and host, so root@localhost is not interchangeable with another root host row. Use the exact existing host only after confirming that it is the account your client should use. Also verify that you are connected to the intended server rather than a different socket, container, or instance.

The requested plugin is unavailable

Authentication-plugin names and defaults vary by MySQL release and by MariaDB. Confirm the server banner with SELECT VERSION(); and inspect the installed package before repeating the change. Do not assume that an older mysql_native_password recipe is appropriate for a current MySQL 8 server. Use a plugin supported by the installed server and by every client that must connect.

The password works in the shell but not in the application

Compare the application’s user, host, port, socket or TCP setting, and client-library capabilities with the values used in your manual test. A different host can select a different MySQL account row, and an older client may not negotiate caching_sha2_password. Correct the connection configuration or update the client; do not solve a host mismatch by exposing root remotely.

A remote root login is being requested

Do not make the root account a remote application credential. The safer design is to keep root local, remove externally accessible root accounts when appropriate, and create a separate account limited to the application’s required schemas and operations. If remote administration is necessary, use the organization’s controlled administrative access path rather than opening unrestricted database root access.

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

The server is MariaDB rather than MySQL

Read the server banner and package name before executing MySQL-specific plugin statements. MariaDB and MySQL can differ in authentication syntax, plugin names, and package defaults. A command copied from this MySQL procedure may fail or produce a different security result on MariaDB; follow the documentation for the server that is actually running.

Final verification checklist

  • You confirmed the server product and version.
  • You connected with the correct administrative method for the current plugin.
  • You inspected every root row and recorded the exact host value.
  • You decided whether local socket authentication or password authentication fits the server’s use.
  • If using a password, you selected a supported plugin and a strong, unique secret.
  • You tested mysql -u root -p or the exact application connection mode required.
  • You kept root local and avoided using it as an application credential.
  • You reviewed mysql_secure_installation prompts instead of accepting them blindly.

The underlying guidance is consistent across the relevant documentation: Ubuntu’s current Server documentation explains the initial auth_socket login; Oracle’s MySQL 8.0 Reference Manual documents ALTER USER with an IDENTIFIED BY clause for changing an existing password; MySQL’s 2025 security guide documents local socket authentication; and the Ubuntu Noble manpage lists the hardening utility’s root-account, anonymous-user, and test-database actions. Their version and package scope matter, so verify the installation in front of you before applying a command.

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.