On this tutorial we will learn how to install MySQL version 8.0.27 database on Ubuntu 20.04 LTS operating system.
Introduction
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 is also used by many popular websites, including Facebook,Flickr,MediaWiki,Twitter,YouTube, etc. MySQL is a component of the LAMP web application software stack, which is an acronym for Linux, Apache, MySQL, Perl/PHP/Python. MySQL is used by many database-driven web applications, including Drupal, Joomla, phpBB, and WordPress. On this tutorial will learn how to install MySQL version 8.0 on an Ubuntu 20.04 server.
Installing MySQL 8 On Ubuntu 20.04
On this installation tutorial, we will use the latest stable of MySQL APT repository which provides deb packages for installing and managing the MySQL server, client, and other components on the current Debian and Ubuntu releases. The MySQL installation will consist of several stages, namely:
- Add and Download MySQL APT Repository
- Update Ubuntu System
- Installing MySQL 8 with APT
- Securing MySQL 8 Database
- Log in To MySQL server
- Install MySQL Client
Adding MySQL APT Repository
By using curl command line, we will download a MySQL 8 APT repository and install it by using dpkg command line.
$ curl -OL https://dev.mysql.com/get/mysql-apt-config_0.8.20-1_all.deb $ sudo dpkg -i mysql-apt-config_0.8.20-1_all.deb
The output will be as shown below :
mpik@worker1:~$ curl -OL https://dev.mysql.com/get/mysql-apt-config_0.8.20-1_all.deb % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0 100 35548 100 35548 0 0 19345 0 0:00:01 0:00:01 --:--:-- 50782
mpik@worker1:~$ sudo dpkg -i mysql-apt-config_0.8.20-1_all.deb [sudo] password for mpik: Selecting previously unselected package mysql-apt-config. (Reading database ... 231220 files and directories currently installed.) Preparing to unpack mysql-apt-config_0.8.20-1_all.deb ... Unpacking mysql-apt-config (0.8.20-1) ... Setting up mysql-apt-config (0.8.20-1) ... Warning: apt-key should not be used in scripts (called from postinst maintainerscript of the package mysql-apt-config) OK
Update Ubuntu Repository
After adding MySQL 8 APT repository, then we will update our Ubuntu 20.04 system by submitting command line :
$ sudo apt-get update
The output :
mpik@worker1:~$ sudo apt-get update Hit:1 http://packages.microsoft.com/repos/code stable InRelease Get:2 http://repo.mysql.com/apt/ubuntu focal InRelease [12.2 kB] Hit:3 https://packages.microsoft.com/repos/vscode stable InRelease Hit:4 https://download.mono-project.com/repo/ubuntu stable-focal InRelease Hit:5 http://us.archive.ubuntu.com/ubuntu focal InRelease . . . Get:17 http://repo.mysql.com/apt/ubuntu focal/mysql-tools i386 Packages [424 B] Fetched 30.1 kB in 3s (8,891 B/s) Reading package lists... Done
Installing MySQL 8 Server on Ubuntu 20.04
On this stage, we will install MySQL 8 on Ubuntu 20.04 server by submitting command line :
$ sudo apt install mysql-server
The output will be :
mpik@worker1:~$ sudo apt install mysql-server Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: chromium-bsu-data fonts-uralic libalut0 libglc0 libglewmx1.13 libgtkglext1 libminizip1 libopenal-data libopenal1 libpangox-1.0-0 libsdl2-2.0-0 libsdl2-image-2.0-0 libsndio7.0 linux-headers-5.11.0-41-generic linux-hwe-5.11-headers-5.11.0-41 linux-image-5.11.0-41-generic linux-modules-5.11.0-41-generic linux-modules-extra-5.11.0-41-generic Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: libaio1 libmecab2 mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client mysql-common mysql-community-client mysql-community-client-core mysql-community-client-plugins mysql-community-server mysql-community-server-core The following NEW packages will be installed: libaio1 libmecab2 mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client mysql-community-client mysql-community-client-core mysql-community-client-plugins mysql-community-server mysql-community-server-core mysql-server The following packages will be upgraded: mysql-common 1 upgraded, 12 newly installed, 0 to remove and 316 not upgraded. Need to get 34.1 MB of archives. After this operation, 285 MB of additional disk space will be used. . . . update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.service. Setting up mysql-server (8.0.27-1ubuntu20.04) ... Processing triggers for man-db (2.9.1-1) ... Processing triggers for libc-bin (2.31-0ubuntu9) ...
By default MySQL database service is running after installation was completed done. We will verify the installation by querying its service and version. These task can be done by submitting following command lines :
$ sudo systemctl status mysql $ mysql --version
The output will be shown below :
mpik@worker1:~$ sudo systemctl status mysql ● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2022-01-11 06:49:54 PST; 2min 6s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 6137 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (code=exited, status=0/SUCCESS) Main PID: 6176 (mysqld) Status: "Server is operational" Tasks: 37 (limit: 9430) Memory: 353.1M CGroup: /system.slice/mysql.service └─6176 /usr/sbin/mysqld
Jan 11 06:49:53 worker1.otodiginet.com systemd[1]: Starting MySQL Community Server... Jan 11 06:49:54 worker1.otodiginet.com systemd[1]: Started MySQL Community Server.
mpik@worker1:~$ mysql --version mysql Ver 8.0.27 for Linux on x86_64 (MySQL Community Server - GPL)
Securing MySQL 8 Installation
After MySQL 8 installation was completed done, it is recommended to secure our fresh installation by submitting command line :
$ sudo mysql_secure_installation
The output will be.
mpik@worker1:~$ sudo mysql_secure_installation
Securing the MySQL server deployment. Enter password for user root: VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: Y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2 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!
mpik@worker1:~$ mysqladmin -u root -p version Enter password: mysqladmin Ver 8.0.27 for Linux on x86_64 (MySQL Community Server - GPL) Copyright (c) 2000, 2021, 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. Server version 8.0.27 Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/run/mysqld/mysqld.sock Uptime: 11 min 2 sec Threads: 2 Questions: 14 Slow queries: 0 Opens: 130 Flush tables: 3 Open tables: 49 Queries per second avg: 0.021 Log in To MySQL 8 Database
On this stage, we will try to log in to MySQL database that was installed, then we will try any query to verify the installation. We will use the following command lines.
$ sudo mysql -u root -p
The output will be shown below :
mpik@worker1:~$ sudo mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 12 Server version: 8.0.27 MySQL Community Server - GPL Copyright (c) 2000, 2021, 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.01 sec) mysql> show variables where Variable_name = "version"; +---------------+--------+ | Variable_name | Value | +---------------+--------+ | version | 8.0.27 | +---------------+--------+ 1 row in set (0.01 sec) mysql> show variables like "%version%"; +--------------------------+-------------------------------+ | Variable_name | Value | +--------------------------+-------------------------------+ | admin_tls_version | TLSv1,TLSv1.1,TLSv1.2,TLSv1.3 | | immediate_server_version | 999999 | | innodb_version | 8.0.27 | | original_server_version | 999999 | | protocol_version | 10 | | replica_type_conversions | | | slave_type_conversions | | | tls_version | TLSv1,TLSv1.1,TLSv1.2,TLSv1.3 | | version | 8.0.27 | | version_comment | MySQL Community Server - GPL | | version_compile_machine | x86_64 | | version_compile_os | Linux | | version_compile_zlib | 1.2.11 | +--------------------------+-------------------------------+ 13 rows in set (0.00 sec) mysql>
Installing MySQL Client
On this stage, we will install MySQL 8 Client. MySQL client is used to connect to MySQL server and do the request and get the response from server, by using query script.
$ sudo apt-get install libmysqlclient21
The output will be as shown below :
mpik@worker1:~$ sudo apt-get install libmysqlclient21 Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: chromium-bsu-data fonts-uralic libalut0 libglc0 libglewmx1.13 libgtkglext1 libminizip1 libopenal-data libopenal1 libpangox-1.0-0 libsdl2-2.0-0 libsdl2-image-2.0-0 libsndio7.0 linux-headers-5.11.0-41-generic linux-hwe-5.11-headers-5.11.0-41 linux-image-5.11.0-41-generic linux-modules-5.11.0-41-generic linux-modules-extra-5.11.0-41-generic Use 'sudo apt autoremove' to remove them. The following packages will be upgraded: libmysqlclient21 1 upgraded, 0 newly installed, 0 to remove and 315 not upgraded. Need to get 1,369 kB of archives. After this operation, 15.4 kB of additional disk space will be used. Get:1 http://repo.mysql.com/apt/ubuntu focal/mysql-8.0 amd64 libmysqlclient21 amd64 8.0.27-1ubuntu20.04 [1,369 kB] Fetched 1,369 kB in 2s (801 kB/s) (Reading database ... 231527 files and directories currently installed.) Preparing to unpack .../libmysqlclient21_8.0.27-1ubuntu20.04_amd64.deb ... Unpacking libmysqlclient21:amd64 (8.0.27-1ubuntu20.04) over (8.0.27-0ubuntu0.20.04.1) ... Setting up libmysqlclient21:amd64 (8.0.27-1ubuntu20.04) ... Processing triggers for libc-bin (2.31-0ubuntu9) ... mpik@worker1:~$ mysql -V mysql Ver 8.0.27 for Linux on x86_64 (MySQL Community Server - GPL)
Conclusion
On this short tutorial, we have discussed how to install MySQL 8 server and client application, also securing MySQL installation. I hope this article will be helpful for anyone who are searching for MySQL installation guide.
Pingback: How To Install Jira On Ubuntu 22.04 LTS - bckinfo.com