Skip to content

Instantly share code, notes, and snippets.

@alexwebgr
Last active May 3, 2025 14:27
Show Gist options
  • Save alexwebgr/e438dcbb1eba91af8131736cfbfe9b80 to your computer and use it in GitHub Desktop.
Save alexwebgr/e438dcbb1eba91af8131736cfbfe9b80 to your computer and use it in GitHub Desktop.
Install MySQL on ubuntu 20.04 and set the root password
# Completely remove any previous config
sudo apt remove --purge mysql*
sudo apt autoremove
sudo find / -iname mysql
# install the server
sudo apt update
sudo apt install mysql-server
# run the wizard
sudo mysql_secure_installation
sudo mysql
mysql> use mysql;
mysql> SELECT user,authentication_string,plugin,host FROM mysql.user;
# enable password login
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'password';
mysql> FLUSH PRIVILEGES;
mysql> exit;
# should be able to login with password now
mysql -u root -p
Enter password:
mysql>
@alexwebgr
Copy link
Author

alexwebgr commented Aug 26, 2023 via email

@DitherDude
Copy link

No, it means failed logon attempt - so one of two things:

  1. Line 11 you used mysql instead of sudo mysql, and were thus unable to bypass the logon requirement. Your current (device) username happens to be root.

  2. Line 21 you forgot the -p flag - and thus attempts to connect without a password - however line 16 you just set one...

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