Score:0

New MySQL install has no root password, and can't set one

cn flag

Just installed MySQL 8 on ubuntu server 20.04.

I can login with mysql -u root, but no matter how I try to set a root password, when I login again it doesn't ask for password.

Does passwords need to be enabled somehow?

tried: ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyN3wP4ssw0rd'; flush privileges;

it completed ok, but no password is enabled.

tried: UPDATE mysql.user SET password=PASSWORD("my-new-password") WHERE User='root';

this gives syntax error.

Score:1
in flag

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.

gabogabans avatar
hk flag
when should I run mysql_secure_installation then? is it even needed with mysql 8.3?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.