{"id":5615,"date":"2020-04-28T00:23:22","date_gmt":"2020-04-27T21:23:22","guid":{"rendered":"https:\/\/kifarunix.com\/?p=5615"},"modified":"2024-03-14T20:09:44","modified_gmt":"2024-03-14T17:09:44","slug":"install-mysql-8-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-mysql-8-on-ubuntu-20-04\/","title":{"rendered":"Install MySQL 8 on Ubuntu 20.04"},"content":{"rendered":"\n<p>This guide provides a step-wise tutorial on how to install MySQL 8 on Ubuntu 20.04. <a rel=\"noreferrer noopener\" href=\"https:\/\/www.mysql.com\/\" target=\"_blank\">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<h2 class=\"wp-block-heading\">Installing MySQL 8 on Ubuntu 20.04<\/h2>\n\n\n\n<p>Ubuntu 20.04 ships with MySQL 8 on its default repositories.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt show mysql-server<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>Package: mysql-server\n<strong>Version: 8.0.19-0ubuntu5<\/strong>\nPriority: optional\nSection: database\n<strong>Source: mysql-8.0<\/strong>\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers <a href=\"mailto:ubuntu-devel-discuss@lists.ubuntu.com\">ubuntu-devel-discuss@lists.ubuntu.com<\/a>\nOriginal-Maintainer: Debian MySQL Maintainers <a href=\"mailto:pkg-mysql-maint@lists.alioth.debian.org\">pkg-mysql-maint@lists.alioth.debian.org<\/a>\nBugs: https:\/\/bugs.launchpad.net\/ubuntu\/+filebug\nInstalled-Size: 110 kB\nDepends: mysql-server-8.0\nHomepage: http:\/\/dev.mysql.com\/\nTask: lamp-server\nDownload-Size: 9,544 B\n<strong>APT-Sources: http:\/\/us.archive.ubuntu.com\/ubuntu focal\/main amd64 Packages<\/strong>\n<\/code><\/pre>\n\n\n\n<p>This makes the installation of MySQL 8 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-preformatted\"><code>apt update\napt upgrade<\/code><\/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\"><code>apt install mysql-server<\/code><\/pre>\n\n\n\n<p>The command installs MySQL 8 and all required package dependency.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Secure MySQL 8 Installation on Ubuntu 20.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<h3 class=\"wp-block-heading\">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.19-0ubuntu5 for Linux on x86_64 ((Ubuntu))<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">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<pre class=\"wp-block-preformatted\"><code>mysql -u root -p<\/code><\/pre>\n\n\n\n<p>Another thing to note is that by default, 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 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>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| immediate_server_version | 999999                        |\n| innodb_version           | 8.0.19                        |\n| original_server_version  | 999999                        |\n| protocol_version         | 10                            |\n| slave_type_conversions   |                               |\n| tls_version              | TLSv1,TLSv1.1,TLSv1.2,TLSv1.3 |\n<strong>| version                  | 8.0.19-0ubuntu5 <\/strong>              |\n| version_comment          | (Ubuntu)                      |\n| version_compile_machine  | x86_64                        |\n| version_compile_os       | Linux                         |\n| version_compile_zlib     | 1.2.11                        |\n+--------------------------+-------------------------------+\n11 rows in set (0.00 sec)\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Enable Password-Based MySQL Authentication<\/h3>\n\n\n\n<p>As mentioned above, MySQL 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>Want to Master SQL? Check out the link below;<\/p>\n\n\n\n<a href=\"https:\/\/imp.i115008.net\/c\/2935865\/828410\/11298\" target=\"_top\" id=\"828410\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"\/\/a.impactradius-go.com\/display-ad\/11298-828410\" border=\"0\" alt=\"\" width=\"162\" height=\"135\" title=\"\"><\/a><img loading=\"lazy\" decoding=\"async\" height=\"0\" width=\"0\" src=\"https:\/\/imp.pxf.io\/i\/2935865\/828410\/11298\" style=\"position:absolute;visibility:hidden;\" border=\"0\" alt=\"\" title=\"\">\n\n\n\n<p>That marks the end of our guide.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">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 20.04. MySQL is a fast, stable and true multi-user, multi-threaded SQL<\/p>\n","protected":false},"author":1,"featured_media":10150,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,299,929],"tags":[1508,1505,1506,1504,1507],"class_list":["post-5615","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","category-database","category-mysql","tag-install-mysql-8-on-ubuntu-20-04","tag-install-mysql-ubuntu-20-04","tag-mysql-8-native-password-plugin","tag-mysql-8-ubuntu-20-04","tag-mysql-auth_socket","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\/5615"}],"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=5615"}],"version-history":[{"count":7,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/5615\/revisions"}],"predecessor-version":[{"id":21354,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/5615\/revisions\/21354"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/10150"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=5615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=5615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=5615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}