Skip to content

Instantly share code, notes, and snippets.

@wwwted
Created February 15, 2021 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wwwted/6d3cff6c671adf955c4a605bc39b8645 to your computer and use it in GitHub Desktop.
Save wwwted/6d3cff6c671adf955c4a605bc39b8645 to your computer and use it in GitHub Desktop.
script to fire up a MySQL instance
#!/bin/bash
MySQL_BIN="/home/ted/src/mysql-8.0.22-linux-glibc2.12-x86_64"
MySQL_HOME="/home/ted/sandboxes/cluster/node1"
## Do not touch below ;)
echo "1) Create MySQL instance"
# If $MySQL_HOME/data exists, stop MySQL + remove all
if [ -d $MySQL_HOME/data ] ; then
echo "1.5) Cleanup ...."
$MySQL_BIN/bin/mysqladmin -uroot -S$MySQL_HOME/mysql.sock shutdown
rm -fr $MySQL_HOME/data
fi
echo "2) Create folders for MySQL"
mkdir -p ${MySQL_HOME}/data
echo "3) Initialize and start MySQL"
${MySQL_BIN}/bin/mysqld --no-defaults --initialize-insecure --datadir=${MySQL_HOME}/data --basedir=${MySQL_BIN}
${MySQL_BIN}/bin/mysqld_safe --defaults-file=${MySQL_HOME}/my.cnf --ledir=${MySQL_BIN}/bin &
while [ ! -S ${MySQL_HOME}/mysql.sock ]
do
echo "Waiting for MySQL to start..."
sleep 2
done
echo "4) Create user ted/ted"
${MySQL_BIN}/bin/mysql -uroot -S${MySQL_HOME}/mysql.sock -e"SET SQL_LOG_BIN=0; CREATE USER 'ted'@'%' IDENTIFIED BY 'ted'; GRANT ALL ON *.* TO 'ted'@'%' WITH GRANT OPTION";
pgrep mysql
${MySQL_BIN}/bin/mysql -uted -pted -S${MySQL_HOME}/mysql.sock -e"status"
${MySQL_BIN}/bin/mysql -uted -pted -S${MySQL_HOME}/mysql.sock -e "select @@hostname, @@global.gtid_executed"
echo "5) Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment