How to: Install and setup MySQL on Ubuntu 20.04 Print

  • 2

Overview

This tutorial will explain how to install MySQL On Ubuntu 20.04. At the time of writing this, you can also use this tutorial for Ubuntu 18.04

Installation

1. First, login to your VPS/Dedicated Server using SSH. If you don't know how to do this, you can follow this guide: [How to connect to a VPS using SSH](https://help.novonode.com/en/article/how-to-connect-to-a-vps-5wcqzs/).
2. Next, you should update your packages on your server by running the following command: `sudo apt update`
3. You now need to install the mysql-server package by running `sudo apt install mysql-server`. You may be prompted to enter "Y" on your keyboard.
4. Once installed, you need to configure the installation by running `sudo mysql_secure_installation`. This command will run you through step-by-step on how to configure your MySQL Server. See below for values that you should enter

Setup

* The Validate Password Plugin will ensure that passwords used are long and secure. It's good practice to select "Y" for this step to protect your database(s).
* If you selected yes, you will then be asked for the level of security that you want to impose. We recommend using either option 2 or 3.
* You will then be prompted to enter a password for your root user. This must be secure and comply with the security rule that you selected above. You will also need to repeat this password for verification purposes.
* Next, you'll be prompted to remove anonymous users and the test database - It's good practice by accepting this.
* Finally, you get an option to disable remote logins. If you're planning to connect locally to your database, you can disable this for better security.

Configuration

1. To start the configuration of your new MySQL server, you need to run `sudo mysql`. This will connect you to a MySQL session.

Create a user in SQL

To create a user, run the following command:
`CREATE USER '(username)'@'localhost' IDENTIFIED WITH mysql_native_password BY '(password)';`.
For example if I wanted my user to be "xenforo" and my password to be "9293***@^@£^@^£as2", the command would be:
`CREATE USER 'xenforo'@'localhost' IDENTIFIED WITH mysql_native_password BY '9293***@^@£^@^£as2';`.

Grant ALL privileges to a MySQL User

To grant all privileges to a MySQL user, run the command:
`GRANT ALL PRIVILEGES ON * . * TO '(username)'@'localhost' WITH GRANT OPTION;`
You then need to flush your privileges by running `FLUSH PRIVILEGES;`.

Create a database in SQL

Simply run the following command to create a database in SQL:
`CREATE DATABASE (database_name);`

2. Once you have concluded the work needed in SQL, you can return to your SSH session by running the command `exit`.

Conclusion

Thank you for reading this tutorial. If you have any issues, contact our team via a Support Ticket!


Was this answer helpful?

« Back