How to install MySQL server on Ubuntu Linux

by time news

2023-10-16 08:30:00

The MySQL Community Server is a popular, open source, cross-platform database management system that supports SQL y NoSQL and has a pluggable storage engine architecture.

Furthermore, it also comes with multiple database connectors for different programming languages, allowing you to develop applications using any of the well-known languages ​​and many other features.

It has many use cases in document storage, cloud, high availability systems, IoT (Internet of Things), hadoop, big data, data warehouse, stack LAMP o LEMP to support high-volume websites/applications and much more.

In this article, we will explain a new database system installation MySQL 8.0 in the versions Ubuntu 22.04 , Ubuntu 20.04 y Ubuntu 18.04 . Before moving on to the actual installation steps, let’s look at a summary of:

What’s new in MySQL 8.0 The database now includes a transactional data dictionary. Comes with support for Atomic DDL statements. Improved security and account management. Improvements in resource management. Various InnoDB improvements. A new type of backup lock. The default character set has changed to utf8mb4 from latin1. A couple of JSON improvements. It comes with support for regular expressions using International Components for Unicode (ICU). New error log that now uses the MySQL component architecture. Improvements in MySQL replication. Supports common table expressions (both recursive and non-recursive). It has an improved optimizer. Additional window functions and more.

table of Contents

What’s New in MySQL 8.0 Step 1: Upgrade Ubuntu Server Step 2: Install MySQL on Ubuntu Server Step 3: Manage MySQL Server via Systemd Step 4: Set MySQL Root Password Step 5: Securely Install MySQL Server Step 6 – Create a MySQL database with the user Step 7: Install additional MySQL products and components

Step 1: Update Ubuntu Server

Fortunately, you can use the package repository APT default to install the server, client and other components de MySQL . At the time of writing this article, the available MySQL version is 8.0.28.

To install it, you need to update the package index on your Ubuntu server by running the following apt commands.

$ sudo apt update
$ sudo apt upgrade

Next, use the apt-cache command (query the package cache) to search for MySQL client and server packages on your Ubuntu server.

$ apt-cache search mysql-server

mysql-server – MySQL database server (metapackage depending on the latest version)
mysql-server-8.0 – MySQL database server binaries and system database setup
mysql-server-core-8.0 – MySQL database server binaries
default-mysql-server – MySQL database server binaries and system database setup (metapackage)
default-mysql-server-core – MySQL database server binaries (metapackage)
mariadb-server-10.6 – MariaDB database server binaries
mariadb-server-core-10.6 – MariaDB database core server files

Step 2 – Install MySQL on Ubuntu Server

Then run the following command to install packages for the community server MySQL the client and the common database files.

$ sudo apt-get install mysql-server

Install MySQL 8.0 on Ubuntu 18.04

The default MySQL configuration file and an error log file will be located in the following location; You can view them using the nano editor or the tail command as shown.

$ sudo nano /etc/mi.cnf
$ sudo tail -f /var/log/mysql/error.log

Step 3: Manage MySQL Server via Systemd

On Ubuntu, after installing the server package MySQL , their services usually start automatically once the package is configured. You can check if the server MySQL It is up and running using the following systemctl command.

$ sudo systemctl status mysql.service

Check MySQL Server Status

If for one reason or another, it does not start automatically, use the following commands to start and enable it to start at system boot time, as follows.

$ sudo systemctl start mysql.service
$ sudo systemctl status mysql.service
$ sudo systemctl start mysql.service
$ sudo systemctl restart mysql.service

Step 4: Set MySQL Root Password

First, open the indicator de MySQL :

$ sudo mysql

Then run the following ALTER USER command to set the MySQL root password using the authentication method mysql_native_password as shown.

mysql> ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘YOUR-STRONG-PASSWORD‘;

After setting the password, exit the prompt de MySQL :

mysql> exit

Set MySQL password in Ubuntu

Step 5: Secure MySQL Server Installation

By default, the installation de MySQL It’s not safe. To protect it, run the security script that comes with the binary package.

$ sudo mysql_secure_installation

You will be asked to enter the password the root which you just configured above.

Then enter yes/ya to the following security questions:

Delete anonymous users? (Press y|Y for Yeah , any other key for No):y Do not allow root login remotely? (Press y|Y for Yeah , any other key for No):y Delete the test database and access it? (Press y|Y for Yeah , any other key for No):y Reload privilege tables now? (Press y|Y for Yeah any other key for No):y

Secure MySQL on Ubuntu

To further protect your MySQL server, read our article 12 MySQL Security Best Practices for Linux.

Step 6: Create a MySQL database with the user

Installation de MySQL It comes with a root account, which you can use to manage the entire database, but for security reasons, I suggest you create a normal user account with limited privileges for the databases, as shown.

$ mysql -u root -p
mysql> CREATE DATABASE Linuxpartydb;
mysql> CREATE USER ‘aaron’@’localhost’ IDENTIFIED BY ‘rig!43B#web1rdl0gn1’;
mysql> GRANT ALL PRIVILEGES ON Linuxpartydb.* TO ‘aaron’@’localhost’;

Now, to log in as your new MySQL user, use the following command.

$ mysql -u aaron -p

Create MySQL database with user

Step 7: Install additional MySQL products and components

Additionally, you can install components MySQL additional information that you consider necessary to work with the server, such as mysql-workbench-community , libmysqlclient18 and many others.

$ sudo apt-get update
$ sudo apt-get install mysql-workbench-community libmysqlclient18

Finally, to access the shell MySQL issue the following command.

$ sudo mysql -u root -p

Connect to the MySQL server

That’s all! In this article, we have explained how to install MySQL in Ubuntu 22.04 y Ubuntu 20.04 . If you have any questions or ideas to share, please use the comment form below to contact us.

#install #MySQL #server #Ubuntu #Linux

You may also like

Leave a Comment