-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_mysq_password.sh
38 lines (38 loc) · 1.24 KB
/
set_mysq_password.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
logger "reseting mysql password"
if [ -f /home/ubuntu/.my.cnf ] ; then
exit 0
fi
export DEBIAN_FRONTEND=noninteractive
apt-get install pwgen
NEW_PW=`pwgen -1cns`
mysqladmin -u root -psupersecret password $NEW_PW
cat << EOF > /home/ubuntu/.my.cnf
# Do not delete this file.
[client]
user = root
password = $NEW_PW
EOF
chown ubuntu:ubuntu /home/ubuntu/.my.cnf
logger "mysql password reset complete"
/etc/init.d/mysql stop
grep -q /data01 /proc/mounts
if [ $? -eq 0 ] ; then
if [ -d /data01/mysql_server ] ; then
exit 0
fi
mkdir /data01/mysql_server
( cd /var/lib/; tar cf - mysql ) | ( cd /data01/mysql_server/ ; tar xfp -)
mv /var/lib/mysql /var/lib/mysql.old
ln -s /data01/mysql_server/mysql /var/lib/mysql
# And apparmor ( Thanks hb5 )
echo >> /etc/apparmor.d/local/usr.sbin.mysqld
echo "/data01/mysql_server/mysql/ r," >> /etc/apparmor.d/local/usr.sbin.mysqld
echo "/data01/mysql_server/mysql/** rwk," >> /etc/apparmor.d/local/usr.sbin.mysqld
/etc/init.d/apparmor start
fi
# 512MB for the OS and then 80% of the rest
INNODB=`cat /proc/meminfo | awk '/MemTotal:/ {printf("%d", .8*(($2-(512*1024)))/1024)}'`
sed -e 's/^# . InnoDB.*$/# \* InnoDB \ninnodb_buffer_pool_size = '$INNODB'M/' -i /etc/mysql/my.cnf
sleep 10
reboot