In this guide we are going through the process of installing and configuring mysql server 8 in Ubuntu 20.04. We will also test our installation by creating a database and a user.
MySQL is one of the popular open-source relational database management system. It is commonly installed as part of the popular LAMP or LEMP (Linux, Apache/Nginx, MySQL/MariaDB, PHP/Python/Perl) stack.
Related Content:
- How to Install and Set Up mysql 8 on Ubuntu 22.04
- How to install Mysql 8 on Rocky Linux/Centos 8
- How to install and Configure Mysql Server 8 on Fedora 34/35
- Mysql Permissions – Create, Update, Delete Database Users
- How to run Mysql 8 with Docker and Docker-Compose
- Install and Setup Nginx, WordPress and Mysql 8 in Centos 8
- Create an RDS instance in terraform with a Mariadb Example
- Using Ansible to Install and Initialize Mysql 8 on Centos 8
Preprequisites
To follow along this guide, ensure you have the following:
- Up to date Ubuntu Server 20.04 with Internet access
- Server root access or user with sudo acces
Ensure our ubuntu server is up to date
Before proceeding let us ensure that the ubuntu server is up to date. First update the repos then do a system upgrade to ensure all the installed packages are up to date:
In your terminal, type these. The -y
option in apt upgrade
is to ensure that the system doesn’t pause for us to accept the upgrade.
|
|
Set up the repo for mysql 8 installation
Mysql server 8 is not available in the default ubuntu repositories. The mysql team provides a downloadable .deb
file that will configure the repositories for mysql server 8 installation. Download it with this command:
|
|
You should see an output almost similar to this:
|
|
Once the download is done, we need to install the downloaded deb file. Use this command to install:
|
|
This will open a configuration window prompting you to choose mysql server version and other components such as cluster, shared client libraries, or the MySQL workbench.
For now since we are only interested in the Mysql Server Installation, leave the default settings and click OK to proceed.
This is the output on successful installation and configuration.
|
|
Install Mysql 8 Server
Now that the repos have been added to include mysql server, we can now install the mysql-server package. First, refresh the repositories to get the latest from the added repo:
|
|
Then Install Mysql 8 Server using this command:
|
|
Enter your administrator credentials, and the system will install the MySQL server package, client packages, and database common files.
The installation will prompt you to enter and confirm a root user and password for the MySQL database.
After that you will be asked to select Authentication plugin. It is recommended that you choose to use a strong password:
After that the new password will be set and service reloaded.
Confirm that mysql server is up and running with this command:
|
|
The Active: active (running) since ...
portion in the above shows that the app is up and running.
Test connection to mysql with the root password
Now that mysql is all set up and is running, we need to confirm that it can accept connections.
To test, connect to mysql with root user mysql -h 127.0.0.1 -u root -p
Output:
|
|
Check mysql version to confirm that everything is Ok:
|
|
Extra - Creating users in mysql
To connect remotely to mysql, it is recommended to create an app specific user and a database. Let us do that here.
To create a database, use this command in the mysql prompt; This command creates a. database called citizix_db
.
|
|
To create a user, use this in the mysql prompt; this command will create a user citizix_user
that can connect from anywhere with the specified password:
|
|
Now grant the created user all privileges on the created database:
|
|
Confirm that you can connect as the new user. Use the mysql
command on the terminal specifying the host with -h
and user with -u
. Also supply the password prompt flag -p
then enter the password:
|
|
Confirm the permissions we have using these commands:
|
|
Up to this point, we have been able to install mysql server 8 on Ubuntu 20.04 and tested that its working as expected by adding some user and a database.