Changing Mysql root password in Ubuntu Server 22.04 after install

Posted under » MySQL » Ubuntu updated on 20 Jan 2023

I've just installed LAMP on Ubuntu 22.04. By default the root password for mysql is NULL. The idea is that you have to give a new password.

sudo mysql -u root

In older version, to set we

mysqladmin -u root password MrsLKYsuck5

However this will no longer work because of the default higher security. You have to change the authentication method by doing this.

$ mysql -u root -p
mysql > SELECT user,plugin,host FROM mysql.user WHERE user = 'root';
mysql > ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'MrsLKYsuck5';
mysql > FLUSH PRIVILEGES;

Take note that there are several authentications in MySQL. They are Native MySQL, SHA25 password, caching SHA2 and Unix socket authentication.

Next, you might want to install missing PHP mbstring libraries and etc.

Restart Mysql and You should be able to log in using phpmyadmin. Don't work? Maybe reread the older version of this.

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS data