版本以及操作系统: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中文网2017-04-17 16:45:20
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!';
ringa_lee2017-04-17 16:45:20
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;