Skip to content

Instantly share code, notes, and snippets.

@retronav
Created August 23, 2021 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save retronav/dd334f825eb70dd387017fbae7ecffa5 to your computer and use it in GitHub Desktop.
Save retronav/dd334f825eb70dd387017fbae7ecffa5 to your computer and use it in GitHub Desktop.
Install MySQL on Ubuntu 20.04 LTS (WSL2)

This method works for me. Use-cases for MySQL for me are:

  1. Connecting to it via Python
  2. Normal CRUD operations

I AM NO MYSQL EXPERT, BUT I WOULD RECOMMEND TO DO THIS ONLY ON YOUR LOCAL SYSTEM. DON'T DO THIS ON A SERVER. I'D NOT BE RESPONSIBLE FOR THE MESS YOU'VE CREATED.

  1. Install it
sudo apt install mysql-server
sudo service mysql start
  1. Run this command, it will open the MySQL shell.
sudo mysql
  1. This command will check the plugins used by various accounts.
mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;

Notice the following entry:

| root             |                                                                        | auth_socket           | localhost |

You should be having this entry after a fresh install.

  1. Change the password (and use caching_sha2_password)
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'YOUR_PASS';
FLUSH PRIVILEGES;
  1. Done. check if we got it updated
| root             | SOME_GARBAGE_HERE_THAT_SHOULDNT_BE_REVEALED | caching_sha2_password | localhost |
  1. Good. Now type exit and quit the mysql shell.
  2. Try logging in again with mysql -u root -p
  3. If the shell pops up, good job! You're lucky enough. You did it. If you didn't, surf StackOverflow, or Super User. There are many solutions.

If you feel anything is wrong here, let me know :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment