{"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
This guide provides a step-wise tutorial on how to install MySQL 8 on Ubuntu 20.04. 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 MySQL 8 Reference Manual<\/a>.<\/p>\n\n\n\n Ubuntu 20.04 ships with MySQL 8 on its default repositories.<\/p>\n\n\n\n This makes the installation of MySQL 8 a seamless task.<\/p>\n\n\n\n Before you can proceed, update and upgrade your system packages.<\/p>\n\n\n\n Next, install MySQL 8 by executing the command below;<\/p>\n\n\n\n The command installs MySQL 8 and all required package dependency.<\/p>\n\n\n\n MySQL ships with a security script called The script can be simply execute by running;<\/p>\n\n\n\n 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 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 You can verify the version of MySQL installed by executing;<\/p>\n\n\n\n You can now connect to MySQL 8 as a root user with the password you just set above.<\/p>\n\n\n\n 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 Therefore, running either of the commands below logs you in to MySQL server;<\/p>\n\n\n\n Once logged in to MySQL, you can as well check the version by executing the command;<\/p>\n\n\n\n As mentioned above, MySQL uses unix socket authentication plugin by default.<\/p>\n\n\n\n To enable password based authentication, you need to switch to MySQL native password plugin, Once that is done, reset root user password;<\/p>\n\n\n\n Reload privileges tables;<\/p>\n\n\n\n Verify the changes;<\/p>\n\n\n\n Exit the database connection and try to login as root again;<\/p>\n\n\n\n There you go. You have disabled no password authentication for MySQL root user on your localhost.<\/p>\n\n\n\n Want to Master SQL? Check out the link below;<\/p>\n\n\n\n That marks the end of our guide.<\/p>\n\n\n\n Install MySQL 8 on CentOS 8<\/a><\/p>\n\n\n\n Install MySQL 8 on Debian 10 Buster<\/a><\/p>\n\n\n\nInstalling MySQL 8 on Ubuntu 20.04<\/h2>\n\n\n\n
apt show mysql-server<\/code><\/pre>\n\n\n\n
Package: mysql-server\nVersion: 8.0.19-0ubuntu5<\/strong>\nPriority: optional\nSection: database\nSource: mysql-8.0<\/strong>\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers ubuntu-devel-discuss@lists.ubuntu.com<\/a>\nOriginal-Maintainer: Debian MySQL Maintainers 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\nAPT-Sources: http:\/\/us.archive.ubuntu.com\/ubuntu focal\/main amd64 Packages<\/strong>\n<\/code><\/pre>\n\n\n\n
apt update\napt upgrade<\/code><\/pre>\n\n\n\n
apt install mysql-server<\/code><\/pre>\n\n\n\n
Secure MySQL 8 Installation on Ubuntu 20.04<\/h3>\n\n\n\n
mysql_secure_installation<\/code> that enables you to implement initial security of MySQL installation in the following ways: <\/p>\n\n\n\n
\n
mysql_secure_installation<\/code><\/pre>\n\n\n\n
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\nPress y|Y for Yes, any other key for No: y<\/strong>\n\nThere are three levels of password validation policy:\n\nLOW Length >= 8\nMEDIUM Length >= 8, numeric, mixed case, and special characters\nSTRONG Length >= 8, numeric, mixed case, special characters and dictionary file\n\nPlease enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2<\/strong>\n...\n<\/code><\/pre>\n\n\n\n
Checking the Version of MySQL Installed<\/h3>\n\n\n\n
mysql -V<\/code><\/pre>\n\n\n\n
mysql Ver 8.0.19-0ubuntu5 for Linux on x86_64 ((Ubuntu))<\/code><\/pre>\n\n\n\n
Logging in to MySQL 8<\/h3>\n\n\n\n
mysql -u root -p<\/code><\/pre>\n\n\n\n
mysql<\/code><\/pre>\n\n\n\n
mysql -u root<\/code><\/pre>\n\n\n\n
mysql> SHOW VARIABLES LIKE \"%version%\";<\/strong><\/code><\/pre>\n\n\n\n
+--------------------------+-------------------------------+\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| 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
Enable Password-Based MySQL Authentication<\/h3>\n\n\n\n
SELECT plugin from mysql.user where User='root';<\/code><\/pre>\n\n\n\n
+-------------+\n| plugin |\n+-------------+\n| auth_socket <\/strong>|\n+-------------+\n1 row in set (0.00 sec)\n<\/code><\/pre>\n\n\n\n
mysql_native_password<\/strong><\/code>.<\/p>\n\n\n\n
UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'root' AND plugin = 'auth_socket';<\/code><\/pre>\n\n\n\n
ALTER USER root@localhost identified with mysql_native_password by 'myStr0nP@ssW0rd';<\/code><\/pre>\n\n\n\n
flush privileges;<\/code><\/pre>\n\n\n\n
SELECT User,plugin from mysql.user where User='root';<\/code><\/pre>\n\n\n\n
+------+-----------------------+\n| User | plugin |\n+------+-----------------------+\n| root | mysql_native_password |\n+------+-----------------------+\n1 row in set (0.00 sec)\n<\/code><\/pre>\n\n\n\n
mysql -u root<\/code><\/pre>\n\n\n\n
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)<\/code><\/pre>\n\n\n\n
mysql<\/code><\/pre>\n\n\n\n
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)<\/code><\/pre>\n\n\n\n
<\/a> \n\n\n\n
Related Tutorials<\/h3>\n\n\n\n