问题
I had to install mysql 8.0 because previous version were crashing.
Now I'm struggling with setting root password. The default empty password doesn't work, I've tried root
, mysql
as passwords but they are not working.
I've created the init file to reset password. Unfortunately, my passwords are not accepted, here is my log:
2018-02-16T10:12:22.962733Z 0 [Warning] [MY-010139] Changed limits: max_open_files: 5000 (requested 8161)
2018-02-16T10:12:22.962815Z 0 [Warning] [MY-010142] Changed limits: table_open_cache: 2419 (requested 4000)
2018-02-16T10:12:23.160066Z 0 [System] [MY-010116] /usr/sbin/mysqld (mysqld 8.0.4-rc-log) starting as process 20059 ...
2018-02-16T10:12:24.013727Z 0 [Warning] [MY-010068] CA certificate ca.pem is self signed.
2018-02-16T10:12:24.026122Z 0 [Warning] [MY-010319] Found invalid password for user: 'root@localhost'; Ignoring user
2018-02-16T10:12:24.043758Z 6 [Warning] [MY-010319] Found invalid password for user: 'root@localhost'; Ignoring user
2018-02-16T10:12:24.050668Z 0 [System] [MY-010931] /usr/sbin/mysqld: ready for connections. Version: '8.0.4-rc-log' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server (GPL).
Here is my current init file content:
SET GLOBAL validate_password.policy = 'LOW';
UPDATE mysql.user
SET authentication_string = PASSWORD('new_password'), password_expired = 'N'
WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;
I've tried so much different passwords, none worked. I've tried to create passwords longer than 16 characters with special characters and numbers, nothing. Any advices what I could do to reset the password and actually start using DB?
回答1:
I had the same problem. Looks like they changed the initial authentication steps with the new version. Instructions are given here. Basically:
$ sudo service mysqld start
$ sudo grep 'temporary password' /var/log/mysqld.log
(use that password in the following - or to log into mysql_secure_installation)
$ mysql -uroot -p
> ALTER USER 'root'@'localhost' IDENTIFIED BY 'newPasswd';
Note: they also switched from the validate_password "plugin" to a "component" - so if you don't need the levels of security they insist on and want a password you can remember, you'll have to run the following within mysql:
> UNINSTALL COMPONENT 'file://component_validate_password';
Edit: They've also changed the authentication plugin to support better encryption. If you're using Workbench or other add-ons and get an error along these lines
Authentication plugin 'caching_sha2_password' cannot be loaded:
/usr/local/mysql/lib/plugin/caching_sha2_password.so not found
Then use the following to adjust the user password:
> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'newPasswd';
You should probably also add (or uncomment if already there) the following line to /etc/my.cnf
default-authentication-plugin=mysql_native_password
回答2:
If you want execute mysql init file you need to pass --init-file
option to mysqld executable when starting it.
You can initialize your MySQL Server instance with --initialize-insecure
https://dev.mysql.com/doc/refman/8.0/en/server-options.html#option_mysqld_initialize-insecure to set empty password for root.
You can also start mysqld with --skip-grant-tables
to connect to mysql without any authorization checks to reset root password. It is recommended to start with --skip-networking
option and connect to mysql using unix sockets to minimize exposure of mysql server for other users.
回答3:
If you can log in to your MySQL server and you wanto to change your password by query you can do it by:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
or removing the root password:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';
Thanks to this blog: https://juejin.im/entry/5b06698cf265da0db3501fdd
回答4:
If you have not reset your password yet, while enter the following command:
mysql_secure_installation
it will ask for the root password. Do you know what is the root password? Find it here:
cat /var/log/mysqld.log
Here you can find the default password for root. Then run the following command:
mysql_secure_installation
Then put that password. After that put a New password. A weak password will be allowed in mysql server 8. So try to put a password like hash password. Retype that password and done. :)
来源:https://stackoverflow.com/questions/48824572/i-installed-mysql-8-x-using-yum-but-i-cannot-find-or-reset-the-root-password