VOOZH about

URL: https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-20-04?comment=190269

⇱ How to Install MySQL on Ubuntu – Step-by-Step Guide | DigitalOcean


How to Install MySQL on Ubuntu – Step-by-Step Guide

Updated on January 23, 2026
Not using Ubuntu 20.04?
Choose a different version or distribution.
Ubuntu 20.04
👁 How to Install MySQL on Ubuntu – Step-by-Step Guide

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the author(s)

👁 Mark Drake
Mark Drake
Author
Manager, Developer Education
See author profile

Former Technical Writer at DigitalOcean. Focused on SysAdmin topics including Debian 11, Ubuntu 22.04, Ubuntu 20.04, Databases, SQL and PostgreSQL.

👁 Anish Singh Walia
Anish Singh Walia
Editor
Sr Technical Content Strategist and Team Lead
See author profile

I help Businesses scale with AI x SEO x (authentic) Content that revives traffic and keeps leads flowing | 3,000,000+ Average monthly readers on Medium | Sr Technical Writer(Team Lead) @ DigitalOcean | Ex-Cloud Consultant @ AMEX | Ex-Site Reliability Engineer(DevOps)@Nutanix

👁 Vinayak Baranwal
Vinayak Baranwal
Editor
Technical Writer II
See author profile

Building future-ready infrastructure with Linux, Cloud, and DevOps. Full Stack Developer & System Administrator. Technical Writer @ DigitalOcean | GitHub Contributor | Passionate about Docker, PostgreSQL, and Open Source | Exploring NLP & AI-TensorFlow | Nailed over 50+ deployments across production environments.

Still looking for an answer?

Was this helpful?

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Hello,

How I can install MySQL 5? This is very important to me for using Magento 1 version.

Thank you.

I have this error at mysql_secure_installation :

Re-enter new password: … Failed! Error: Password hash should be a 41-digit hexadecimal number

For those who wonder why this isn’t working, it is because sudo apt install mysql-server install latest version of mysql, which is mysql 8 or latest. mysql 5.7 installation need to refers to other tutorial

hi

I followed your tutorial on ubuntu 16.4 and it seems to be working all fine, now I have another question, my software instruction asks: the table engine must be “MyISAM”. With new MySQL versionit’s always InnoDB. Set “default-storage-engine” option to “MyISAM” in “/etc/mysql/my.cnf”

can you guide me on how to do that?

Thanks

Hello Mark, Thanks for the share of this tutorial, it helped me a lot, First time I do this without any issues and very clear all your steps on this article. Appreciate it. Thank You.

On Ubuntu 20.04, fresh mysql installation. In step 3 when setting up a new user, Plugin 'authentication_plugin' is not loaded.

This will not work on a server with 512mb RAM. To fix, add some swap space.

But you can add some swap fairly easily. I used the instructions at this link, but there were some other good simple tutorials if this no longer works: https://salslab.com/a/running-mysql-on-a-vps-with-512mb-ram/

“sudo mysql_secure_installation” on a brand-new Ubuntu 20.04 provided by Digital Ocean gave the following error after attempting to set the root password:

“Failed! Error: SET PASSWORD has no significance for user ‘root’@‘localhost’ as the authentication method used doesn’t store authentication data in the MySQL server. Please consider using ALTER USER instead if you want to change authentication parameters.”

So to workaround this, use CTRL-C to cancel the mysql_secure_installation script and do the following:

sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by '<rootpassword>';
quit

Then you can run “sudo mysql_secure_installation” again and this time, decline the option to change the root password so you can perform the other steps of the script.

Note that once this is set, you’ll access mysql with the password, like so, instead of just “sudo mysql”

mysql -u root -p

I recently ran into the issue of not being able to log in after Step 2- mysql_secure_installation in WSL2

sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
exit
sudo mysql_secure_installation 
# various prompts within this step

mysql -u root -p



mysql -u root -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (13)

What worked was using TCP connection to connect rather than a socket connection

mysql -u root -p --protocol=tcp

OR use sudo

sudo mysql -u root -p
[sudo] password for vivek: <---- the sudo user password
Enter password: <---- mysql password

👁 Creative Commons
This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License.
  • Deploy on DigitalOcean

    Click below to sign up for DigitalOcean's virtual machines, Databases, and AIML products.

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and AI-native businesses

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

© 2026 DigitalOcean, LLC.Sitemap.
Dark mode is coming soon.