-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmysql-ramdisk-setup.sh
executable file
·51 lines (41 loc) · 2.01 KB
/
mysql-ramdisk-setup.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
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# Inspired by http://kotega.com/blog/2010/apr/12/mysql-ramdisk-osx/
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $DIR/mysql-ramdisk-config.sh
echo "*** Creating ramdisk"
RAMDISK_BLOCKS=$(($RAMDISK_SIZE_MB * 1048576 / 512))
diskutil erasevolume HFS+ "mysql-ramdisk" `hdiutil attach -nomount ram://$RAMDISK_BLOCKS`
echo ; echo "*** Initialising DB in ramdisk"
$MYSQL_PATH/bin/mysqld --initialize \
--user mysql \
--basedir=/usr/local/opt/[email protected] \
--datadir=$RAMDISK_MOUNT_POINT/mysql-ramdisk 2> /tmp/mysql-ramdisk-init.log ; cat /tmp/mysql-ramdisk-init.log
TEMP_PW=`cat /tmp/mysql-ramdisk-init.log | sed -n 's/.*A temporary password is generated for root@localhost: \(.*\)$/\1/p'` && rm /tmp/mysql-ramdisk-init.log
if [[ -z TEMP_PW ]] ; then
echo ; echo "!!! Unable to retrieve temporary password"
exit 1
fi
echo ; echo "*** Starting mysqld"
$MYSQL_PATH/bin/mysqld --basedir=/usr/local/opt/[email protected] \
--datadir=$RAMDISK_MOUNT_POINT/mysql-ramdisk \
--user=mysql \
--log-error=$RAMDISK_MOUNT_POINT/mysql-ramdisk/mysql.ramdisk.err \
--pid-file=/$RAMDISK_MOUNT_POINT/mysql-ramdisk/mysql.ramdisk.pid \
--port=3308 \
--socket=/tmp/mysql-ram.sock \
$MYSQLD_OPTIONS &
while [ ! -e $RAMDISK_MOUNT_POINT/mysql-ramdisk/mysql.ramdisk.pid ] ; do
sleep 2
done
echo "*** pid is:" `cat $RAMDISK_MOUNT_POINT/mysql-ramdisk/mysql.ramdisk.pid `
echo ; echo "*** Changing mysql root password"
$MYSQL_PATH/bin/mysql -uroot \
--socket=/tmp/mysql-ram.sock \
-p$TEMP_PW \
--connect-expired-password \
-e "ALTER USER 'root'@'localhost' IDENTIFIED BY '$MYSQL_ROOT_PASSWORD';"
unset TEMP_PW
if [[ ! -z ENVIRONMENT_SETUP_COMMANDS ]]; then
echo ; echo "*** Setting up environment"
eval $ENVIRONMENT_SETUP_COMMANDS
fi