Jump to content

[Shell] MySQL Installer


tierrilopes
 Share

Recommended Posts

Script to:

  • Install mysql55-server
  • Remove default users
  • Generate random remote user with 12 length
  • Generate random password with 64 length

 

Script code:

#!/bin/sh
#### MySQL Installer ####
#### tierrilopes ####
#### tlthings.net ####
#Installation passwords
v_gen_password=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 60 | head -n 1)
v_gen_remote_user=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 12 | head -n 1)
v_gen_mysqladmin_password=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 60 | head -n 1)
#Color stuff
cecho () { echo -e "\033[36m$1\033[0m"; }
echo Updating system and installing packges...
pkg update && pkg upgrade -y && pkg install -y mysql55-server wget
echo Configuring mysql-server...
pwd_mkdb -p /etc/master.passwd
sysrc mysql_enable="YES"
service mysql-server start
#makes sure enough time passed to start mysql-server
sleep 5
#Gives max permissions to folders and sub-folders
chown -R mysql /var/db/mysql chgrp -R mysql /var/db/mysql
## Set localhost default admin password
/usr/local/bin/mysqladmin -uroot password "$v_gen_mysqladmin_password"
##Create remote access mysql user
echo Creating mysql user with remote access...
mysql -uroot -p$v_gen_mysqladmin_password mysql -e"DROP DATABASE IF EXISTS test;"
mysql -uroot -p$v_gen_mysqladmin_password mysql -e"DELETE FROM mysql.user WHERE Host='';"
mysql -uroot -p$v_gen_mysqladmin_password mysql -e"DELETE FROM mysql.user WHERE Host='%';"
mysql -uroot -p$v_gen_mysqladmin_password mysql -e"DELETE FROM mysql.user WHERE Password='';"
mysql -uroot -p$v_gen_mysqladmin_password mysql -e"GRANT ALL PRIVILEGES ON *.* TO '$v_gen_remote_user'@'%' IDENTIFIED BY '$v_gen_password' WITH GRANT OPTION;"
mysql -uroot -p$v_gen_mysqladmin_password mysql -e"FLUSH PRIVILEGES;"
#Outputs MySQL information
echo MySQL remote user: $v_gen_remote_user
echo -e MySQL remote password: $v_gen_password
echo -e MySQL IP address: $(wget checkip.dyndns.org:80 --no-check-certificate -O - -o /dev/null | cut -d" " -f6 | sed 's/<\/body><\/html>//')
echo
cecho "MySQL installation completed"
cecho "tierrilopes"
cecho "tlthings.net"

 

NOTE: TO BE USED ON A FRESH INSTALL OF FREEBSD

 

Regards,

Tierri Lopes.

 

mysql_installer.sh

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...