Last active
April 8, 2016 07:07
-
-
Save thde/22e70b503a6604216dc461227deeb3b1 to your computer and use it in GitHub Desktop.
A script to set a new user password after migrating from MySQL to 5.5
This file contains hidden or 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 | |
# mygrator.sh v0.1 | |
# | |
# Usage: mygrator.sh USER PASSWORD | |
set -x | |
MYSQLUSER="${1}" | |
MYSQLPASS="${2}" | |
if ! echo "${MYSQLUSER}" | grep -q -E '^[a-z0-9]*_[a-zA-Z0-9]*$'; then | |
echo "User ${MYSQLUSER} not valid!" | |
exit 1 | |
fi | |
if [ -z "${MYSQLPASS}" ] ; then | |
echo "No Password!" | |
exit 1 | |
fi | |
mysql << EOF | |
UPDATE mysql.user SET plugin = '' WHERE plugin = 'mysql_old_password' AND user = '${MYSQLUSER}'; | |
FLUSH PRIVILEGES; | |
SET SESSION old_passwords = 0; | |
UPDATE mysql.user SET Password=PASSWORD('${MYSQLPASS}') WHERE USER='${MYSQLUSER}'; | |
FLUSH PRIVILEGES; | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment