How to Configure MYSQL on DreamCompute running Debian or Ubuntu

MySQL is one of the most popular database engines used for websites. MySQL is an important part of LAMP (Linux, Apache, MySQL, PHP) stacks as well as other AMP stacks, and is supported by many web software packages.

MySQL is the only relational database software offered by DreamHost for its Shared, VPS, and Dedicated hosting products. This article helps you install and configure it on a DreamCompute running Debian or Ubuntu.

Installing MySQL

Debian and Ubuntu sometimes offer multiple versions of MySQL in case your needs require an older version, however it is usually best to go with the default version if there are no specific requirements needed.

To install the default version of MySQL on your system, run the following commands:

user@server:$ sudo apt-get update
user@server:$ sudo apt-get install -y mysql-server

Before the installation completes, a dialog will pop up asking you to specify a MySQL server root password.

Viewing installed packages

You can check which packages were just install by running the following command:

user@server:$ dpkg -l | grep mysql

ii  mysql-client-5.7        5.7.21-0ubuntu0.16.04.1   amd64   MySQL database client binaries
ii  mysql-client-core-5.7   5.7.21-0ubuntu0.16.04.1   amd64   MySQL database core client binaries
ii  mysql-common            5.7.21-0ubuntu0.16.04.1   all     MySQL database common files, e.g. /etc/mysql/my.cnf
ii  mysql-server            5.7.21-0ubuntu0.16.04.1   all     MySQL database server (metapackage depending on the latest version)
ii  mysql-server-5.7        5.7.21-0ubuntu0.16.04.1   amd64   MySQL database server binaries and system database setup
ii  mysql-server-core-5.7   5.7.21-0ubuntu0.16.04.1   amd64   MySQL database server binaries

Configuring and using MySQL

The configuration files are stored in the /etc/mysql directory.

user@server:$ ls -1 /etc/mysql

The /etc/mysql/mysql.conf.d/mysqld.cnf config file

There are a few settings you may wish to change to customize MySQL. The following changes can be made in the /etc/mysql/mysql.conf.d/mysqld.cnf file.

Change the 'bind' address

Edit this file and you'll see the bind address:

bind-address   =

This is the IP address MySQL is listening to. It can only listen to one IP address at any time. By default it will listen to (aka localhost), meaning that the MySQL service will only be accessible from the instance it is installed on.

If you want to connect to MySQL from other DreamCompute instances, you can change this to your database instance's IPv4 or IPv6 IP address. Here is what an IPv6 configured mysql bind-address would look like:

bind-address   = 2607:f298:6050:8a28:f816:3eff:fe62:c9c3


This value is the largest size allowed for a single packet, which normally is only relevant for restoring backups. If a backup was created on a server with a high setting for this value, it may have difficulty restoring on another machine with a lower setting. The default is 16M.

Restarting the mysql service

If any changes are made to your mysql configuration, you must restart MySQL for it to read the them. This can be done by running the following:

user@server:$ sudo service mysql restart

Connecting to the mysql shell

If you need to set up new databases or configure new users, you must log into your MySQL Shell. Run any of the following command to log in.

user@server:$ mysql -u root -p

The prompt will change to the following:


You can now run mysql commands to configure a database.

Secure MySQL

After MySQL has been installed, it's a good idea to secure its settings. Run the following command to open an interactive settings dialog:

user@server:$ mysql_secure_installation

Securing the MySQL server deployment.
Enter password for user root:

Set a value for password validation

You can choose to enable the 'Password Plugin' which tests the strength of your MySQL passwords. If you want to enable this, type the letter 'y'. You can then decide how secure you'd like new passwords to be.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2

Changing your root password

The dialog will ask you if you want to change your root password. This isn't necessary since you just created it while installing.

Using existing password for root.

Estimated strength of the password: 50
Change the password for root ? ((Press y|Y for Yes, any other key for No) : n

 ... skipping.

Disable the anonymous user

It's a good idea to disable the anonymous user.

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y

Disable root login

It is also recommended to disable root login.

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y

Remove 'test' database

You should remove the 'test' database since there's no need for it.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...

 - Removing privileges on test database...


Reload so your new settings take affect.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

All done!

Did this article answer your questions?

Article last updated .