简体   繁体   中英

MySQL 5.7.20 unable to set root password

I installed MySQL Server 5.7.20 on ubuntu 14.04 and i can log in to server using:

mysql -u root -p

password is blank...how can i set mysql root password in terminal before install mysql server?

I installed it using silent install and try to run from terminal this mysql query:

SET PASSWORD FOR 'root'@'localhost' = 'mypasswordhere';

But i im getting this:

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> SHOW warnings;
+-------+------+------------------------------------------------------------------------------------------------------------+
| Level | Code | Message                                                                                                    |
+-------+------+------------------------------------------------------------------------------------------------------------+
| Note  | 1699 | SET PASSWORD has no significance for user 'root'@'localhost' as authentication plugin does not support it. |
+-------+------+------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

So what i im doing wrong? I just want to change from blank password for user root to mypasswordhere password...how it needs to be done?

Try

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mypasswordhere';

From https://www.percona.com/blog/2016/03/16/change-user-password-in-mysql-5-7-with-plugin-auth_socket/

If you install 5.7 and don't provide a password to the root user, it will use the auth_socket plugin. That plugin doesn't care and doesn't need a password. It just checks if the user is connecting using a UNIX socket and then compares the username. If we want to configure a password, we need to change the plugin and set the password at the same time, in the same command.

After installing Mysql on Ubuntu and similar one should run mysql_secure_installation command .

It clears some possible problems and one of the things is it asks for a new root password.

But previous answer from @Valuator will change the password.

user1433049 suggests to use mysql_secure_installation. However, this does not help: Also mysql_secure_installation does not change the root password in this situation. That's what brought me here.

(This is actually a comment/correction to the answer above. However, I cannot comment due to low reputation. If someone can transfer it to a comment, please delete this answer.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM