{"id":12451,"date":"2022-04-30T17:46:20","date_gmt":"2022-04-30T14:46:20","guid":{"rendered":"https:\/\/kifarunix.com\/?p=12451"},"modified":"2024-03-09T11:37:53","modified_gmt":"2024-03-09T08:37:53","slug":"install-mysql-8-on-ubuntu","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-mysql-8-on-ubuntu\/","title":{"rendered":"Install MySQL 8 on Ubuntu 22.04"},"content":{"rendered":"\n<p>This guide provides a step-wise tutorial on how to install MySQL 8 on Ubuntu 22.04. <a href=\"https:\/\/www.mysql.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">MySQL<\/a> is a fast, stable and true multi-user, multi-threaded SQL database server with its main goals being speed, robustness and ease of use. To see a comprehensive description of the features offered by MySQL 8, navigate to <a href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/mysql-nutshell.html\" target=\"_blank\" rel=\"noreferrer noopener\">MySQL 8 Reference Manual<\/a>.<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#install-my-sql-8-on-ubuntu-22-04\">Install MySQL 8 on Ubuntu 22.04<\/a><ul><li><a href=\"#install-my-sql-8-on-ubuntu\">Install MySQL 8 on Ubuntu<\/a><\/li><li><a href=\"#secure-my-sql-8-installation-on-ubuntu-22-04\">Secure MySQL 8 Installation on Ubuntu 22.04<\/a><\/li><li><a href=\"#checking-the-version-of-my-sql-installed\">Checking the Version of MySQL Installed<\/a><\/li><li><a href=\"#logging-in-to-my-sql-8\">Logging in to MySQL 8<\/a><\/li><li><a href=\"#enable-password-based-on-my-sql-8-authentication\">Enable Password-Based on MySQL 8 Authentication<\/a><\/li><li><a href=\"#related-tutorials\">Related Tutorials<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"install-my-sql-8-on-ubuntu-22-04\">Install MySQL 8 on Ubuntu 22.04<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-my-sql-8-on-ubuntu\">Install MySQL 8 on Ubuntu<\/h3>\n\n\n\n<p>Ubuntu 22.04 ships with MySQL 8 on its default repositories. This makes the installation of MySQL 8 on Ubuntu 22.04 a seamless task.<\/p>\n\n\n\n<p>Before you can proceed, update and upgrade your system packages.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo su -<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">apt update<\/pre>\n\n\n\n<p>Next, install MySQL 8 by executing the command below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">apt install mysql-server<\/pre>\n\n\n\n<p>The command installs MySQL 8 and all required package dependencies.<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>Reading package lists... Done\nBuilding dependency tree... Done\nReading state information... Done\nThe following additional packages will be installed:\n  libcgi-fast-perl libcgi-pm-perl libclone-perl libencode-locale-perl libevent-pthreads-2.1-7 libfcgi-bin libfcgi-perl libfcgi0ldbl libhtml-parser-perl\n  libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libmecab2 libprotobuf-lite23 libtimedate-perl\n  liburi-perl 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\nSuggested packages:\n  libdata-dump-perl libipc-sharedcache-perl libbusiness-isbn-perl libwww-perl mailx tinyca\nThe following NEW packages will be installed:\n  libcgi-fast-perl libcgi-pm-perl libclone-perl libencode-locale-perl libevent-pthreads-2.1-7 libfcgi-bin libfcgi-perl libfcgi0ldbl libhtml-parser-perl\n  libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libmecab2 libprotobuf-lite23 libtimedate-perl\n  liburi-perl mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client-8.0 mysql-client-core-8.0 mysql-common mysql-server mysql-server-8.0 mysql-server-core-8.0\n0 upgraded, 28 newly installed, 0 to remove and 3 not upgraded.\nNeed to get 29.0 MB of archives.\nAfter this operation, 240 MB of additional disk space will be used.\nDo you want to continue? [Y\/n] y\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"secure-my-sql-8-installation-on-ubuntu-22-04\">Secure MySQL 8 Installation on Ubuntu 22.04<\/h3>\n\n\n\n<p>MySQL ships with a security script called <code>mysql_secure_installation<\/code> that enables you to implement initial security of MySQL installation in the following ways: <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You can set a password for root accounts.<\/li>\n\n\n\n<li>You can remove root accounts that are accessible from outside the local host.<\/li>\n\n\n\n<li>You can remove anonymous-user accounts.<\/li>\n\n\n\n<li>You can remove the test database (which by default can be accessed by all users, even anonymous users), and privileges that permit anyone to access databases with names that start with test_.<\/li>\n<\/ul>\n\n\n\n<p>The script can be simply execute by running;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mysql_secure_installation<\/code><\/pre>\n\n\n\n<p>When run, the script prompts you on whether you want to implement password complexity checks. Accept the choose the strength of the password;<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>VALIDATE PASSWORD COMPONENT can be used to test passwords\nand improve security. It checks the strength of password\nand allows the users to set only those passwords which are\nsecure enough. Would you like to setup VALIDATE PASSWORD component?\n\n<strong>Press y|Y for Yes, any other key for No: y<\/strong>\n\nThere are three levels of password validation policy:\n\nLOW    Length &gt;= 8\nMEDIUM Length &gt;= 8, numeric, mixed case, and special characters\nSTRONG Length &gt;= 8, numeric, mixed case, special characters and dictionary                  file\n\n<strong>Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2<\/strong>\n...\n<\/code><\/pre>\n\n\n\n<p>Next, set the root password and accept other prompts to remove anonymous database users, disallow remote root login, remove test databases  and reload privileges tables to effect the changes on MySQL.<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>Please set the password for root here.\n\nNew password: \n\nRe-enter new password: \n\nEstimated strength of the password: 100 \nDo you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y\nBy default, a MySQL installation has an anonymous user,\nallowing anyone to log into MySQL without having to have\na user account created for them. This is intended only for\ntesting, and to make the installation go a bit smoother.\nYou should remove them before moving into a production\nenvironment.\n\nRemove anonymous users? (Press y|Y for Yes, any other key for No) : y\nSuccess.\n\n\nNormally, root should only be allowed to connect from\n'localhost'. This ensures that someone cannot guess at\nthe root password from the network.\n\nDisallow root login remotely? (Press y|Y for Yes, any other key for No) : y\nSuccess.\n\nBy default, MySQL comes with a database named 'test' that\nanyone can access. This is also intended only for testing,\nand should be removed before moving into a production\nenvironment.\n\n\nRemove test database and access to it? (Press y|Y for Yes, any other key for No) : y\n - Dropping test database...\nSuccess.\n\n - Removing privileges on test database...\nSuccess.\n\nReloading the privilege tables will ensure that all changes\nmade so far will take effect immediately.\n\nReload privilege tables now? (Press y|Y for Yes, any other key for No) : y\nSuccess.\n\nAll done!\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"checking-the-version-of-my-sql-installed\">Checking the Version of MySQL Installed<\/h3>\n\n\n\n<p>You can verify the version of MySQL installed by executing;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mysql -V<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mysql  Ver 8.0.28-0ubuntu4 for Linux on x86_64 ((Ubuntu))<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"logging-in-to-my-sql-8\">Logging in to MySQL 8<\/h3>\n\n\n\n<p>You can now connect to MySQL 8 as a root user with the password you just set above.<\/p>\n\n\n\n<p>But it is good to note that MySQL 8 uses unix socket authentication plugin by default. This enables you to login to your MySQL server from the localhost as a root user or user with sudo rights without a password.<\/p>\n\n\n\n<p>Therefore, running either of the commands below logs you in to MySQL server;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mysql<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mysql -u root<\/code><\/pre>\n\n\n\n<p>Even when you run the command below, and press enter for empty password when prompted, you should still login.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mysql -u root -p<\/code><\/pre>\n\n\n\n<p>Once logged in to MySQL, you can as well check the version by executing the command;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mysql&gt; <strong>SHOW VARIABLES LIKE \"%version%\";<\/strong><\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>+--------------------------+-----------------+\n| Variable_name            | Value           |\n+--------------------------+-----------------+\n| admin_tls_version        | TLSv1.2,TLSv1.3 |\n| immediate_server_version | 999999          |\n| innodb_version           | 8.0.28          |\n| original_server_version  | 999999          |\n| protocol_version         | 10              |\n| replica_type_conversions |                 |\n| slave_type_conversions   |                 |\n| tls_version              | TLSv1.2,TLSv1.3 |\n| version                  | 8.0.28-0ubuntu4 |\n| version_comment          | (Ubuntu)        |\n| version_compile_machine  | x86_64          |\n| version_compile_os       | Linux           |\n| version_compile_zlib     | 1.2.11          |\n+--------------------------+-----------------+\n13 rows in set (0.02 sec)\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"enable-password-based-on-my-sql-8-authentication\">Enable Password-Based on MySQL 8 Authentication<\/h3>\n\n\n\n<p>As mentioned above, MySQL 8 uses unix socket authentication plugin by default.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>SELECT plugin from mysql.user where User='root';<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>+-------------+\n| plugin      |\n+-------------+\n| <strong>auth_socket <\/strong>|\n+-------------+\n1 row in set (0.00 sec)\n<\/code><\/pre>\n\n\n\n<p>To enable password based authentication, you need to switch to MySQL native password plugin, <code><strong>mysql_native_password<\/strong><\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'root' AND plugin = 'auth_socket';<\/code><\/pre>\n\n\n\n<p>Once that is done, reset root user password;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ALTER USER root@localhost identified with mysql_native_password by 'myStr0nP@ssW0rd';<\/code><\/pre>\n\n\n\n<p>Reload privileges tables;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>flush privileges;<\/code><\/pre>\n\n\n\n<p>Verify the changes;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>SELECT User,plugin from mysql.user where User='root';<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>+------+-----------------------+\n| User | plugin                |\n+------+-----------------------+\n| root | mysql_native_password |\n+------+-----------------------+\n1 row in set (0.00 sec)\n<\/code><\/pre>\n\n\n\n<p>Exit the database connection and try to login as root again;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mysql -u root<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>mysql<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)<\/code><\/pre>\n\n\n\n<p>There you go. You have disabled no password authentication for MySQL root user on your localhost.<\/p>\n\n\n\n<p>That marks the end of our guide on how to install MySQL 8 on Ubuntu.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"related-tutorials\">Related Tutorials<\/h3>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/kifarunix.com\/install-mysql-8-on-centos-8\/\" target=\"_blank\">Install MySQL 8 on CentOS 8<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/kifarunix.com\/install-mysql-8-on-debian-10-buster\/\" target=\"_blank\">Install MySQL 8 on Debian 10 Buster<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/kifarunix.com\/install-mysql-8-on-freebsd-12\/\" target=\"_blank\">Install MySQL 8 on FreeBSD 12<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-mysql-8-on-debian-9\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install MySQL 8 on Debian 9<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This guide provides a step-wise tutorial on how to install MySQL 8 on Ubuntu 22.04. MySQL is a fast, stable and true multi-user, multi-threaded SQL<\/p>\n","protected":false},"author":1,"featured_media":9395,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,299,929],"tags":[4972,4968,4970,4971,4969],"class_list":["post-12451","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","category-database","category-mysql","tag-enable-native-password-for-mysql-8","tag-install-mysql-8-on-ubuntu-22-04","tag-install-mysql-version-8-0-on-an-ubuntu-22-04","tag-mysql-8-authentication","tag-ubuntu-22-04-mysql-8","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/12451"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=12451"}],"version-history":[{"count":5,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/12451\/revisions"}],"predecessor-version":[{"id":20453,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/12451\/revisions\/20453"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/9395"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=12451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=12451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=12451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}