summaryrefslogtreecommitdiff
path: root/files/scripts/CentOS
diff options
context:
space:
mode:
Diffstat (limited to 'files/scripts/CentOS')
-rw-r--r--files/scripts/CentOS/setmysqlpass.sh9
1 files changed, 7 insertions, 2 deletions
diff --git a/files/scripts/CentOS/setmysqlpass.sh b/files/scripts/CentOS/setmysqlpass.sh
index d762a20..01d8fbf 100644
--- a/files/scripts/CentOS/setmysqlpass.sh
+++ b/files/scripts/CentOS/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/')
/sbin/service mysqld stop
/usr/libexec/mysqld --skip-grant-tables --user=root --datadir=/var/lib/mysql/data --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
# chown to be on the safe side
chown mysql.mysql /var/lib/mysql/mysql-bin.*