Set Root MySQL 8 Password

CodeZeus
1 min readJun 15, 2021

For MySQL 8 it’s easy to login once after you’ve installed mysql-server. Do the following.

Login shell as Root

sudo su

Login to MySQL with No Password

Nobody besides you should have root access to your system.

su
mysql -u root --skip-password

Change your Password

Change the part that says yourPassword to whatever you want.

mysql> alter user 'root'@'localhost' identified by 'yourPassword'; flush privileges; exit;

Change Password For Local Development

mysql> alter user 'root'@'localhost' identified with mysql_native_password by 'yourPassword';mysql> grant all privileges on mysql.*, sys.* to 'root'@'localhost' with grant option; exit;

Exit Shell Root, Login As Normal

mysql -u root -p
Enter password: yourPassword

You can use No Password

If you don’t want a localhost password (localhost as in, not your server) you can adjust it this way:

mysql> drop user 'root'@'localhost';
mysql> create user 'root'@'localhost' identified with mysql_native_password by '';
mysql> grant all privileges on mysql.*, sys.* to 'root'@'localhost' with grant option; exit;

You then would log in as any user on the system with:

mysql -u root

--

--

CodeZeus

Software Developer Jesse Boyer, known more by JREAM. Hobbyist and Professional Developer.