How To Install MySQL Community Server 8.0.31 On Ubuntu 22.04

In this short tutorial we will learn how to install MySQL Community Server 8.0.31 on Ubuntu 22.04 LTS operating system. MySQL is an open-source relational database management system (RDBMS), it implements the relational model and uses Structured Query Language to manage its data.

MySQL is free and open-source software under the terms of the GNU General Public License, and is also available under a variety of proprietary licenses. MySQL was owned and sponsored by the Swedish company MySQL AB, which was bought by Sun Microsystems (now Oracle Corporation).

Installing MySQL Community Server 8.0.31 On Ubuntu 22.04

This tutorial is using the latest stabel MySQL Community Server which was released on 11 October 2022. The following are the steps for installing MySQL Community Server on Ubuntu 22.04.

  1. Update Ubuntu 22.04 system
  2. Search MySQL 8 server packages on Ubuntu 22.04 LTS
  3. Install MySQL 8 server package
  4. Securing MySQL 8 server
  5. MySQL Server Service Management
  6. Testing MySQL 8 Server

The detailed tasks above, will be explained in the sub-chapter below.

1. Update Ubuntu 22.04 system

In this step, we will update Ubuntu 22.04 repository system. It is recommended to be always updating our system before installing new packages. This task is to make sure if we are accessing the latest packages versions. To update our packages software we will use command line :

$ sudo apt update
$ sudo apt upgrade

2. Searching MySQL 8 Server Packages on Ubuntu 22.04 LTS

We will install MySQL using the APT package repository. At the time of this writing, the version of MySQL Community Server available in the default Ubuntu repository is version 8.0.31. To ensure if we choose the latest version of MySQL server, we will verify it by submitting command line :

$ apt-cache search mysql-server

Output :

ramans@infodiginet:~$ 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

Then query the info from the package that we will use, by submitting command line :

$ apt info -a mysql-server-8.0

Output :

ramans@infodiginet:~$ apt info -a mysql-server-8.0
Package: mysql-server-8.0
Version: 8.0.31-0ubuntu0.22.04.1
Priority: optional
Section: database
Source: mysql-8.0
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian MySQL Maintainers <pkg-mysql-maint@lists.alioth.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 1.639 kB
Provides: virtual-mysql-server
Pre-Depends: adduser (>= 3.40), debconf, mysql-common (>= 5.5)
Depends: lsb-base (>= 3.0-10), mysql-client-8.0 (>= 8.0.31-0ubuntu0.22.04.1), mysql-common (>= 5.8+1.0.4~), mysql-server-core-8.0 (= 8.0.31-0ubuntu0.22.04.1), passwd, perl:any (>= 5.6), psmisc, debconf (>= 0.5) | debconf-2.0
Recommends: libhtml-template-perl, mecab-ipadic-utf8
Suggests: mailx, tinyca
Conflicts: mariadb-server-10.1, mariadb-server-10.3, mysql-server-5.7, virtual-mysql-server
Homepage: http://dev.mysql.com/
Task: lamp-server
Download-Size: 1.420 kB
APT-Sources: http://id.archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages
Description: MySQL database server binaries and system database setup
MySQL is a fast, stable and true multi-user, multi-threaded SQL database
server. SQL (Structured Query Language) is the most popular database query
language in the world. The main goals of MySQL are speed, robustness and
ease of use.
.
This package contains all the infrastructure needed to setup system
databases.

Package: mysql-server-8.0
Version: 8.0.28-0ubuntu4
Priority: optional
Section: database
Source: mysql-8.0
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian MySQL Maintainers <pkg-mysql-maint@lists.alioth.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 1.603 kB
Provides: virtual-mysql-server
Pre-Depends: adduser (>= 3.40), debconf, mysql-common (>= 5.5)
Depends: lsb-base (>= 3.0-10), mysql-client-8.0 (>= 8.0.28-0ubuntu4), mysql-common (>= 5.8+1.0.4~), mysql-server-core-8.0 (= 8.0.28-0ubuntu4), passwd, perl:any (>= 5.6), psmisc, debconf (>= 0.5) | debconf-2.0
Recommends: libhtml-template-perl, mecab-ipadic-utf8
Suggests: mailx, tinyca
Conflicts: mariadb-server-10.1, mariadb-server-10.3, mysql-server-5.7, virtual-mysql-server
Homepage: http://dev.mysql.com/
Task: lamp-server
Download-Size: 1.386 kB
APT-Sources: http://id.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
Description: MySQL database server binaries and system database setup
MySQL is a fast, stable and true multi-user, multi-threaded SQL database
server. SQL (Structured Query Language) is the most popular database query
language in the world. The main goals of MySQL are speed, robustness and
ease of use.
.
This package contains all the infrastructure needed to setup system
databases.

3. Install MySQL 8 Server Package

After confirming the MySQL Community Server version, then we will do the installation, by submitting command line :

$ sudo apt install mysql-server-8.0

Output :

ramans@infodiginet:~$ sudo apt install mysql-server-8.0
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
libaio1 libcgi-fast-perl libcgi-pm-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-bin
libfcgi-perl libfcgi0ldbl libhtml-template-perl libmecab2 libprotobuf-lite23 mecab-ipadic
mecab-ipadic-utf8 mecab-utils mysql-client-8.0 mysql-client-core-8.0 mysql-common
mysql-server-core-8.0
Suggested packages:
libipc-sharedcache-perl mailx tinyca
The following NEW packages will be installed:
libaio1 libcgi-fast-perl libcgi-pm-perl libevent-core-2.1-7 libevent-pthreads-2.1-7 libfcgi-bin
libfcgi-perl libfcgi0ldbl libhtml-template-perl libmecab2 libprotobuf-lite23 mecab-ipadic
mecab-ipadic-utf8 mecab-utils mysql-client-8.0 mysql-client-core-8.0 mysql-common
mysql-server-8.0 mysql-server-core-8.0
0 upgraded, 19 newly installed, 0 to remove and 2 not upgraded.
Need to get 29,1 MB of archives.
After this operation, 242 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
. . .
done!
update-alternatives: using /var/lib/mecab/dic/ipadic-utf8 to provide /var/lib/mecab/dic/debian (mecab-dictionary) in auto mode
Setting up mysql-server-8.0 (8.0.31-0ubuntu0.22.04.1) ...
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Renaming removed key_buffer and myisam-recover options (if present)
mysqld will log errors to /var/log/mysql/error.log
mysqld is running as pid 8425
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service.
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...

By default, MySQL server service is running after installation is completed done. To check its service, we will use the following command line :

$ sudo systemctl status mysql.service

Output :

ramans@infodiginet:~$ sudo systemctl status mysql.service
[sudo] password for ramans:
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2023-01-02 12:56:57 WIB; 15min ago
Process: 8634 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 8642 (mysqld)
Status: "Server is operational"
Tasks: 38 (limit: 9408)
Memory: 364.3M
CPU: 8.617s
CGroup: /system.slice/mysql.service
└─8642 /usr/sbin/mysqld

Jan 02 12:56:56 infodiginet systemd[1]: Starting MySQL Community Server...
Jan 02 12:56:57 infodiginet systemd[1]: Started MySQL Community Server.
MySQL sever 8.0 service

4. Securing MySQL Community Server 8.0.31

4.1. Setting root Password

Since we do the fresh installations of MySQL, We need to run security script. This script changes some secure default options for things like remote root logins and sample users.  Since July 2022, the mysql_secure_installation script will failed if we run because, the script will attempt to set a password for the installation’s root MySQL account but, by default on Ubuntu installations, this account is not configured to connect using a password.

We will error message as shown below :

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
... Failed! Error: SET PASSWORD has no significance for user 'root'@'localhost' as the authentication method used doesn't store authentication data in the MySQL server. Please consider using ALTER USER instead if you want to change authentication parameters.

To avoid this case, we need to change the root user’s authentication method to one that uses a password. We will use ALTER USER command inside SQL prompt. The following example changes the authentication method to mysql_native_password:

ramans@infodiginet:~$ sudo mysql
[sudo] password for ramans:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.31-0ubuntu0.22.04.1 (Ubuntu)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '11!#fsJIHNlsf8FFret#';
Query OK, 0 rows affected (0,01 sec)
mysql> exit
Bye
MySQL setting root password

4.2. Executing  mysql_secure_installation Script

After root password was set, then we will execute mysql_secure_installation properly, as shown below :

$ sudo mysql_secure_installation

Output :

ramans@infodiginet:~$ sudo mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 11!#fsJIHNlsf8FFret#
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.

Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password:

Re-enter new password:

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Dropping test database...
Success.

- Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

5. MySQL Server Service Management

5.1. Enabling the MySQL server at boot time

In this step, we will ensure if our fresh MySQL server service will be available when boot time. To make it happen we have to enable MySQL Server service enable.

1. Checking if MySQL server 8 service starts when the system boots using the systemctl command:

$ sudo systemctl is-enabled mysql.service

2. if the status is not yet enabled, then we will enable it by submitting command line :

$ sudo systemctl enable mysql.service

3. To verify MySQL server 8 is running properly we wil submit command line :

$ sudo systemctl status mysql.service

Below is an example of enabling MySQL Server service.

ramans@infodiginet:~$ sudo systemctl is-enabled mysql.service
enabled
ramans@infodiginet:~$ sudo systemctl disable mysql.service
Synchronizing state of mysql.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable mysql
Removed /etc/systemd/system/multi-user.target.wants/mysql.service.
ramans@infodiginet:~$ sudo systemctl is-enabled mysql.service
disabled
ramans@infodiginet:~$ sudo systemctl enable mysql.service
Synchronizing state of mysql.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable mysql
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service.
ramans@infodiginet:~$ sudo systemctl status mysql.service
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2023-01-02 12:56:57 WIB; 57min ago
Main PID: 8642 (mysqld)
Status: "Server is operational"
Tasks: 40 (limit: 9408)
Memory: 365.9M
CPU: 31.210s
CGroup: /system.slice/mysql.service
└─8642 /usr/sbin/mysqld

Jan 02 12:56:56 infodiginet systemd[1]: Starting MySQL Community Server...
Jan 02 12:56:57 infodiginet systemd[1]: Started MySQL Community Server.

5.2. Start, restart and Stopping MySQL Server service

The following are the way how to control the MySQL server 8 on Ubuntu 22.04 LTS operating system.

1. Start MySQL Server :

$ sudo systemctl start mysql.service

2. Stop MySQL server :

$ sudo systemctl stop mysql.service

3. Restart MySQL Server :

$ sudo systemctl restart mysql.service

6. Testing MySQL 8 Server

In this step, we have already had MySQL running properly on Ubuntu 22.04 LTS operating system. Then we will test to login and showing version and database which was already exist.

1. Login to MySQL Server

$ mysql -u root -p

Output :

ramans@infodiginet:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.31-0ubuntu0.22.04.1 (Ubuntu)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

2. Show the variables :

mysql> SHOW VARIABLES LIKE "%version%";
+--------------------------+-------------------------+
| Variable_name | Value |
+--------------------------+-------------------------+
| admin_tls_version | TLSv1.2,TLSv1.3 |
| immediate_server_version | 999999 |
| innodb_version | 8.0.31 |
| original_server_version | 999999 |
| protocol_version | 10 |
| replica_type_conversions | |
| slave_type_conversions | |
| tls_version | TLSv1.2,TLSv1.3 |
| version | 8.0.31-0ubuntu0.22.04.1 |
| version_comment | (Ubuntu) |
| version_compile_machine | x86_64 |
| version_compile_os | Linux |
| version_compile_zlib | 1.2.12 |
+--------------------------+-------------------------+
13 rows in set (0,01 sec)

3. Show database :

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0,00 sec)

Conclusion

In this short tutorial we have learned how to install MySQL Server community version on Ubuntu 22.04 LTS operating system. I hope this tutorial can be helpful.

 

(Visited 322 times, 1 visits today)

You may also like