Skip to main content

How to install and secure MySQL on your Linux VPS

Sabrina Goom avatar
Written by Sabrina Goom
Updated over a month ago

To install and secure MySQL on your VPS, do the following:

(for Ubuntu/Debian/CentOS)

Install MySQL with sudo apt install mysql-server (Ubuntu/Debian) or yum install mariadb-server (CentOS), and then start the service with systemctl start mysql or systemctl start mariadb.

After that, run the secure script: mysql_secure_installation

You can then create a user and database:

CREATE DATABASE mydb;
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;

We recommend configuring remote access and setting up a firewall to limit access.

Did this answer your question?