Install MySQL on the Database Server


To get started, we’ll configure one VPS instance as the MySQL server. Having our data stored on a separate computer is a good way to expand gracefully when you’ve hit the ceiling on a one-machine configuration. It also provides the basic structure necessary to load balance and expand your set up even more at a later time.

To get started, we’ll need to install some basic packages on our database server. These will basically be most of the same steps you’d take for setting up a database for a traditional LEMP stack, but we won’t need all of the components (some will be on the other server).

Start off by updating your package cache and installing the MySQL server:

sudo apt-get update
sudo apt-get install mysql-server


Install MySQL on the Database Server

You will be asked to select and confirm a root password for MySQL during the installation procedure.

When you are finished, you need to run the database installation command, which will generate the appropriate directory structure to manage your components.

sudo mysql_install_db


Afterwards, we should tighten up security a little bit by running a script that will ask us about disabling some insecure defaults:

sudo mysql_secure_installation


You will have to enter the MySQL administrator’s password that you set in the steps above. Afterwards, it will ask if you want to change that password. Type “N” for no if you’re happy with your current password.

To all of the additional questions, you should just hit ENTER to select the default options which will remove some test databases and lock down access.