什么是MySQL 5.7的默认根口令

全新安装后,无法像使用其他旧版本的MySQL一样使用root ID和空白/无密码login到MySQL数据库

在linux上新安装MySQL-community-server 5.7之后,您将需要从/var/log/mysqld.log中找到临时密码以root身份登录。

  1. grep 'temporary password' /var/log/mysqld.log
  2. 运行mysql_secure_installation来更改新的密码

ref: http : //dev.mysql.com/doc/refman/5.7/en/linux-installation-yum-repo.html

如果你想安装MySQL或percona无人参与(就像在我的情况下),你可以使用下面的脚本:

 # first part opens mysql log # second part greps lines with temporary password # third part picks last line (most recent one) # last part removes all the line except the password # the result goes into password variable password=$(cat /var/log/mysqld.log | grep "A temporary password is generated for" | tail -1 | sed -n 's/.*root@localhost: //p') # setting new password, you can use $1 and run this script as a file and pass the argument through the script newPassword="wh@teverYouLikE" # resetting temporary password mysql -uroot -p$password -Bse "ALTER USER 'root'@'localhost' IDENTIFIED BY '$newPassword';"