MySQL 8.x does not allow for people to log in as root
unless they also have sudo
-level permissions on the server. This is part of a long list of security enhancements that have gone into the more recent MySQL releases to stem the bad reputation the database engine has received over the last 15 years because bloggers set up a WordPress account using the root
account, then the blog gets taken over by "hackers", then the entire database (and all other systems connected to the same database) are compromised. This isn't only because of people using WordPress, but the practice has been excessively common in that community.
To connect to MySQL as root
, you will need to use sudo
. You will not need to provide a password, because if you have sudo
, you pretty much own the server already:
sudo mysql
Once connected, you can create for yourself an account and grant it all the privileges that account may need. For example, if you need a "SysAdmin" account, you can do something like this:
CREATE USER 'admin'@'localhost' IDENTIFIED WITH mysql_native_password BY 'superSecretPassword!123';
GRANT ALL ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;
From here, you can connect to MySQL the normal way:
mysql -u admin -p
Ideally, the root
account in MySQL is only used when first setting up the system or when fixing something that has gone horribly wrong.