Skip to content

Instantly share code, notes, and snippets.

@imtiazShakil
Last active January 4, 2022 09:58
Show Gist options
  • Select an option

  • Save imtiazShakil/64f52dbc8a0483d2da8e7ac8853f2399 to your computer and use it in GitHub Desktop.

Select an option

Save imtiazShakil/64f52dbc8a0483d2da8e7ac8853f2399 to your computer and use it in GitHub Desktop.
Setup MySQL 8+ on Linux

For Older Linux distributions (Optional)

Download latest apt-config package from mysql and install it: https://dev.mysql.com/downloads/repo/apt/ Make sure you provide the latest release(focal/buster) during apt-package installation.


Install

sudo apt update
sudo apt install mysql-server
sudo mysql_secure_installation 

Configure

Option 1: Use legacy password mode
In Ubuntu systems running MySQL 5.7 (and later versions), the root MySQL user is set to authenticate using the auth_socket plugin by default rather than with a password. This allows for some greater security and usability in many cases, but it can also complicate things when you need to allow an external program (e.g., phpMyAdmin) to access the user.

In order to use a password to connect to MySQL as root, you will need to switch its authentication method from auth_socket to mysql_native_password.
That's why During installation choose legacy password mode (native_authentication_method).

Option 2: Use caching_sha2_password (more secured)

$> sudo mysql
mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'password';
mysql> FLUSH PRIVILEGES;
mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;

Finally you're good to go alhamdulillah. Check if MySQL is running:

service mysql status
mysql -u root -p #in order to login

Optional: Install MySql Workbench (MySQL Client)

As we already have latest apt repository for MySQL, we'll be able to install latest MySQL workbench alhamdulillah.

sudo apt-get  install mysql-workbench-community
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment