How to install MySQL 8.0 server on Ubuntu

  • avatar
  • 1.2K Views
  • 1 Like
  • 8 mins read

MySQL is an open-source relational database management system (RDBMS). Its name is a combination of My and SQL the abbreviation for Structured Query Language. A relational database organizes data into one or more data tables in which data types may be related to each other; these relations help structure the data. SQL is a language programmers use to create, modify and extract data from the relational database, as well as control user access to the database.

Installing MySQL server

MySQL is available and can be installed using the apt packaging system:

sudo apt-get update && sudo apt-get install mysql-server

This will download and install MySQL server but leaves it insecure. To run the wizard and adjust security, execute the following command:

sudo mysql_secure_installation

It will prompt you some security options that you should answer:mysql_security_wizard1.png

mysql_security_wizard2.png

mysql_security_wizard3.png

mysql_security_wizard4.png

mysql_security_wizard5.png

mysql_security_wizard6.png

Checking MySQL server

Usually, MySQL service is automatically started once the package is configured. To check whether the MySQL server is up and running or not, use this command:

sudo systemctl status mysql.service

It will output the current server status:

mysql_status.png

If MySQL server does not automatically start, you can use the following command to start it:

sudo systemctl start mysql

And start it automatically at system startup:

sudo systemctl enable mysql

Connect to MySQL server

To launch the first SQL queries we must connect with the created user (in our case root):

sudo mysql -u root -p

It will prompt for the password of the root account:

mysql_login.png

Now you can run your MySQL queries.

Creating MySQL users (optional)

Previously we used root user to login and run queries. Everything works fine but... it can be insecure.
This user has full privileges over the MySQL server and can insert, update, delete, alter, flush... whole database. Because of this, it's recommended to use a different user for non-administrative tasks.

With successful MySQL connection with root user and inside the server, we can create a new user with the following command:

CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';

Replace the user and password fields with desired values. In our example we will use:

user: mysql_user
pass: hsy7yD5KS9FuQrk!

mysql_user_create.png

After creating new user, appropriate privileges must be granted. The general syntax for granting user privileges is as follows:

GRANT PRIVILEGE ON database.table TO 'user'@'host';

The PRIVILEGE value defines what actions the user is allowed to perform (one or several comma separated) on the specified database and table. You can grant a user privileges globally by entering asterisks (*) instead of the database and table names. Privileges will be granted to the user for the choosen host (it can be localhost, remote IP address or percent (%) for any host).

In our example, we want to grant all privileges on all databases and tables (not recommended in real applications):

GRANT ALL PRIVILEGES ON * . * TO 'mysql_user'@'localhost';

mysql_user_privileges.png

Finally, apply the changes and clear cache:

FLUSH PRIVILEGES;

mysql_user_privileges_flush.png

Your MySQL server is now up and running.

 Join Our Monthly Newsletter

Get the latest news and popular articles to your inbox every month

We never send SPAM nor unsolicited emails

0 Comments

Leave a Reply

Your email address will not be published.

Replying to the message: View original

Hey visitor! Unlock access to featured articles, remove ads and much more - it's free.