Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@alroniks
Created December 6, 2016 20:50
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 alroniks/1352088266157651a60f5f6ee3ba74f5 to your computer and use it in GitHub Desktop.
Save alroniks/1352088266157651a60f5f6ee3ba74f5 to your computer and use it in GitHub Desktop.
Server maintenance scripts
#!/bin/bash
flag=5
if [ ! $1 ]; then
echo "Set user name for connect to mysql"
let flag=flag-1
fi
if [ ! $2 ]; then
echo "Set user password for connect to mysql"
let flag=flag-1
fi
if [ ! $3 ]; then
echo "U must set database name at third parameter"
let flag=flag-1
fi
if [ ! $4 ]; then
echo "U must set user name at fourth parameter"
let flag=flag-1
fi
if [ ! $5 ]; then
echo "U must set user password at fifth parameter"
let flag=flag-1
fi
if [ $flag = 5 ]; then
# create database
mysql -u$1 -p$2 -e "create database $3 character set utf8 collate utf8_unicode_ci;"
mysql -u$1 -p$2 -e "show databases;"
mysql -u$1 -p$2 -e "create user $4;"
mysql -u$1 -p$2 -e "grant all on $3.* to '$4'@'localhost' identified by '$5';"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment