How to install mysql on Ubuntu 16.04

Installation of the MySQL server involves roughly three steps: 1) unpacking the software; 2) creating a default database; 3) creating a default user/password (and storing this in the database).

Should you accidentally lose the database files (usually located in /var/lib/mysql) then you can start again without completely reinstalling the server package. This is done with the command mysqld --initialize. If you run this command while a database is already in place, it will report an error ("File exists") and it won't attempt to overwrite the database. However, if you're unsure if the installation procedure has completed correctly, it's OK to delete the directory /var/lib/mysql and re-initialize the database.

The --initialize flag will cause MySQL to generate a root user and a random password, which is then written to the log file. For more information, see man mysqld.


First check the version of Mysql using mysql --version.

If you have version 5.7.6 or later, the data directory would be initialized automatically and no need for running sudo mysql_install_db.

some more info on installing mysql on DigitalOcean server is on https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-14-04