VOOZH about

URL: https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-16-04

⇱ How To Install MySQL on Ubuntu 16.04 | DigitalOcean


How To Install MySQL on Ubuntu 16.04

Published on November 24, 2016

By Hazel Virdó

staff technical writer

Not using Ubuntu 16.04?
Choose a different version or distribution.
Ubuntu 16.04
👁 How To Install MySQL on Ubuntu 16.04

Introduction

MySQL is an open-source database management system, commonly installed as part of the popular LAMP (Linux, Apache, MySQL, PHP/Python/Perl) stack. It uses a relational database and SQL (Structured Query Language) to manage its data.

The short version of the installation is simple: update your package index, install the mysql-server package, and then run the included security script.

  1. sudo apt-get update
  2. sudo apt-get install mysql-server
  3. mysql_secure_installation

This tutorial will explain how to install MySQL version 5.7 on a Ubuntu 16.04 server. However, if you’re looking to update an existing MySQL installation to version 5.7, you can read this MySQL 5.7 update guide instead.

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

👁 Hazel Virdó
Hazel Virdó
Author
staff technical writer
See author profile

former DO tech editor publishing articles here with the community, then founded the DO product docs team (https://do.co/docs). to all of my authors: you are incredible. working with you was a gift. love is what makes us great.

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!

If it occurs error because of broken MySQL package on Ubuntu 16.04. Just do this trick

# Purge all MySQL packages
sudo apt purge mysql*
sudo rm -rf /var/lib/mysql
sudo rm -rf /etc/mysql

# Reinstall MySQL
sudo apt install mysql-server mysql-client

Hey, There was no prompt for root password as mentioned in Step 1 :/(

This worked for me.

https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04

(use dd if=/dev/zero of=/swapfile bs=1M count=1024 if you have cheap plan, and don’t forget to purge and remove certain files as mentioned)

change mysqladmin -p -u root version to sudo mysqladmin -p -u root version to test the installation

sudo systemctl mysql start is the wrong command to manually start the service, the proper command is sudo systemctl start mysql

Thank You, worked for me :)

I haven’t had to mess with the swap file to get mysql to install, as a couple of others have commented. Must thank my lucky stars. :-)

Thanks for taking the time to explain the differences in initializing mysql_install_db between the 5.6 and 5.7 versions of mysql. I find this level of attention of detail in most D.O tutorials and is the reason why I respect them so much.

It’s also worth mentioning that many consider MariaDB a much better alternative to MySQL. Not sure why DO doesn’t have a tutorial for MariaDB and Ubuntu, but they do have one for MariaDB and CentOS. But anyway, the installation instructions and everything else is almost identical. I wrote a tutorial for both MySQL and MariaDB on Ubuntu on my website

After I run ‘sudo apt-get install mysql-server’ Got this feedback:

Reading package lists… Done Building dependency tree
Reading state information… Done E: Unable to locate package mysql-server

What can be wrong here?

👁 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.