mysql5.7 安装后无法设置密码
PHP中文网
PHP中文网 2017-04-17 16:43:20
0
3
814

版本以及操作系统:Server version: 5.7.17-0ubuntu0.16.04.1 (Ubuntu-server)

尝试直接apt-get install mysql-server,安装过程中弹出让输入密码的框都直接回车。

安装好之后,输入mysql可以直接登陆数据库,尝试用mysqladmin -u root password "password"``来设置密码,弹出两条警告:

$ mysqladmin -u root password "123"
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

再次尝试登陆,还是可以直接输入mysql登陆(尝试过重启数据库)。

第二次尝试登陆进数据库,使用update mysql.user set authentication_string=PASSWORD('123123') where user='root';设置,然后刷新权限flush privileges;

再次尝试登陆,还是不用输任何密码就可以登陆成功(有重启数据库)

那么,现在问题来了:

我要怎样才能成功的给数据库设个密码呢?(除了在安装时弹出框里输入)

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(3)
Ty80

The official document has tips here, you can follow the tips
https://dev.mysql.com/doc/mys...
Only for MySQL 5.7: During the initial startup of the server, the following situation occurs, assuming that the server data Directory is empty:
The server has been initialized.
SSL certificate and key files are generated in the data directory.
The validate_password plugin is installed and enabled.
'root'@'localhost' creates a superuser account. The superuser's password is set and stored in the error log file. To display it, use the following command:
shell> sudo grep 'temporary password' /var/log/mysqld.log sudo grep 'temporary password' /var/log/mysqld.log
通过使用生成的临时密码登录并为超级用户帐户设置自定义密码,尽快更改root密码:
shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';Log in by using the generated temporary password and set a custom password for the superuser account , change the root password as soon as possible:
shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

Note🎜 MySQL's validate_password plugin is installed by default. This will require that the password contains at least one uppercase letter, one lowercase letter, one number, and one special character, and that the total password length is at least 8 characters. 🎜
PHPzhong

Try using mysql_secure_installion

左手右手慢动作

There should be an empty account in your account. You have not deleted or set a password for this empty account.
delete from mysql.user where user='';flush privileges;
or
update mysql.user set authentication_string=PASSWORD('123123 ');flush privileges;

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template