summaryrefslogtreecommitdiff
path: root/files/scripts/Debian/setmysqlpass.sh
diff options
context:
space:
mode:
Diffstat (limited to 'files/scripts/Debian/setmysqlpass.sh')
-rw-r--r--files/scripts/Debian/setmysqlpass.sh9
1 files changed, 7 insertions, 2 deletions
diff --git a/files/scripts/Debian/setmysqlpass.sh b/files/scripts/Debian/setmysqlpass.sh
index 427daf0..f7d5357 100644
--- a/files/scripts/Debian/setmysqlpass.sh
+++ b/files/scripts/Debian/setmysqlpass.sh
@@ -1,12 +1,17 @@
#!/bin/sh
-test $# -gt 0 || exit 1
+test -f /root/.my.cnf || exit 1
+
+rootpw=$(grep password /root/.my.cnf | sed -e 's/^[^=]*= *\(.*\) */\1/')
/etc/init.d/mysql stop
/usr/sbin/mysqld --skip-grant-tables --user=root --datadir=/var/lib/mysql --log-bin=/var/lib/mysql/mysql-bin &
sleep 5
-echo "USE mysql; UPDATE user SET Password=PASSWORD('$1') WHERE User='root' AND Host='localhost';" | mysql -u root
+mysql -u root mysql <<EOF
+UPDATE mysql.user SET Password=PASSWORD('$rootpw') WHERE User='root' AND Host='localhost';
+FLUSH PRIVILEGES;
+EOF
killall mysqld
sleep 15
# chown to be on the safe side