This guide provides instructions for installing MySQL or MariaDB on an Ubuntu cloud server, applicable to versions from Ubuntu 16.04 to Ubuntu 20.04.
To install MySQL, use the following command:
$ sudo apt install mysql-server -y
For MariaDB, the installation command is as follows:
$ sudo apt install mariadb-server mariadb-client -y
To configure MySQL to start automatically with the system:
$ sudo systemctl enable mysql
To set MariaDB to start with the system:
$ sudo systemctl enable mariadb.service
Execute the security script, which is the same for both MySQL and MariaDB. Follow the prompts to set the root password; for other prompts, simply press Enter to choose the default options.
$ sudo mysql_secure_installation
Enter current password for root (enter for none):
Set root password? [Y/n]
New password:
Re-enter new password:
Password updated successfully!
Remove anonymous users? [Y/n]
Disallow root login remotely? [Y/n]
Remove test database and access to it? [Y/n]
Reload privilege tables now? [Y/n]
Test the connection as the root user.
# mysql -u root -p -h localhost
Create databases and database users.
> CREATE USER 'test_user'@'localhost' IDENTIFIED BY 'test_pass';
> CREATE DATABASE test_database;
> GRANT ALL PRIVILEGES ON test_database.* TO 'test_user'@'localhost';
Exit the connection.
> quit
23-02-2024 02:02:07
22-02-2024 03:19:32
22-02-2024 03:16:03
22-02-2024 03:14:03
22-02-2024 03:11:58