Technical Help & Resources / Setting Up MySQL

Setting Up MySQL


This guide will help you to install MySQL to your host.

Prerequisites

The commands below can be ran to make sure everything is up to date before continuing.

sudo apt-get update
sudo apt-get upgrade

Installation

Run the following commands to install the MySQL Server and Client

sudo apt-get install mysql-server
sudo apt-get install mysql-client

SupervisorCtl Configuration

To avoid issues with socket files and pid files the locations must be changed.

Edit the supervisor configuration file.

sudo nano /etc/supervisor/conf.d/supervisord.conf

Add the additonal lines to the end of the file.

[program:mysql]
command=/usr/bin/mysqld_safe
user=mysql
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/mysql/mysql.log
environment=MYSQL_ROOT_PASSWORD="Password123",MYSQL_TCP_PORT=3306
pidfile=/var/lib/mysql/mysqld.pid
socket=/var/lib/mysql/mysql.sock

* supervisorctl is the service manager used on your host and it is responsible for running the database in the background.


MySQL Server Configuration

Edit the MySQL server configuration

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

Add the additonal lines of configuration

pid-file =/var/lib/mysql/mysqld.pid
socket =/var/lib/mysql/mysql.sock


MySQL Client Configuration

Edit the MySQL configuration configuration

sudo nano /etc/mysql/mysql.conf.d/mysql.cnf

Add the additonal lines of configuration

socket=/var/lib/mysql/mysql.sock


Reload Changes

To load the changes made you can run the commands below

sudo supervisorctl reread
sudo supervisorctl update

Completing Setup


You should be able now to access your MySQL Server with the command below

sudo mysql -P 3306 -u root -p

To harden your systems security one simple way is to run the command below

sudo mysql_secure_installation

Finally to check the status of the service for MySQL you can call supervisorctl

sudo supervisorctl status mysql