Last active
May 29, 2019 11:53
-
-
Save syneart/d615ba2a87e2f8b24a2a3aeb53f73d67 to your computer and use it in GitHub Desktop.
Set default root password for MySQL 5.7 with Ubuntu when MySQL doesn't ask for root password at installing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | THIS SCRIPT IS TESTED CORRECTLY ON | | |
# |--------------------------------------------------------| | |
# | OS | MySQL | Test | Last test | | |
# |--------|--------------------------|------|-------------| | |
# | Ubuntu | Ver 14.14 Distrib 5.7.26 | OK | 16 May 2019 | | |
MYSQL_ROOT_PASSWORD=`head /dev/urandom | tr -dc A-Za-z0-9 | head -c10` | |
sudo mysql -uroot<<EOF | |
use mysql; | |
update user set authentication_string=password('$MYSQL_ROOT_PASSWORD') where user='root'; | |
update user set plugin="mysql_native_password" where User='root'; | |
flush privileges; | |
EOF | |
(mysql -uroot -p$MYSQL_ROOT_PASSWORD -e ";") >/dev/null 2>&1 && { | |
echo -e "\033[33m[INFO] Temporary password for your mysql's user root: $MYSQL_ROOT_PASSWORD\033[0m" | |
echo "[INFO] You can excute mysql_secure_installation to change ..." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use below command to set default root password for MySQL 5.7 with Ubuntu on your own operating system.
wget -O - https://gist.githubusercontent.com/syneart/d615ba2a87e2f8b24a2a3aeb53f73d67/raw/mysql_native_password.sh | sh