-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43c4f97
commit a525b0b
Showing
4 changed files
with
76 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,17 @@ | ||
#!/bin/bash | ||
#!/usr/bin/env bash | ||
# from: http://jetpackweb.com/blog/2009/07/20/bash-script-to-create-mysql-database-and-user/ | ||
EXPECTED_ARGS=2 | ||
E_BADARGS=65 | ||
|
||
MYSQL=`which mysql` | ||
CURRENT_TIME=$(date "+%Y%m%d-%H%M%S") | ||
FILE_NAME=$CURRENT_TIME'.sql' | ||
|
||
Q1="DROP DATABASE IF EXISTS $1;" | ||
Q2="DROP USER '$2'@'localhost';" | ||
Q3="FLUSH PRIVILEGES;" | ||
SQL="${Q1}${Q2}" | ||
SQL="${Q1}" | ||
|
||
if [ $# -ne $EXPECTED_ARGS ] | ||
then | ||
echo "Usage: $0 dbname dbuser" | ||
exit $E_BADARGS | ||
fi | ||
echo "First I'll need your MySQL root user password to backup your database." | ||
read -sp 'Password: ' PASSVAR | ||
|
||
echo "I'll need your MySQL root user password next." | ||
mkdir -p /var/www/archive | ||
mysqldump -uroot -p$PASSVAR $Q1 > /var/www/archive/$Q1$CURRENT_TIME'.sql' | ||
|
||
$MYSQL -uroot -p -e "$SQL" | ||
$MYSQL -uroot -p$PASSVAR -e "$SQL" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
# from: http://jetpackweb.com/blog/2009/07/20/bash-script-to-create-mysql-database-and-user/ | ||
EXPECTED_ARGS=1 | ||
E_BADARGS=65 | ||
MYSQL=`which mysql` | ||
|
||
Q1="DROP USER '$1'@'localhost';" | ||
Q2="FLUSH PRIVILEGES;" | ||
SQL="${Q1}${Q2}" | ||
|
||
if [ $# -ne $EXPECTED_ARGS ] | ||
then | ||
echo "Usage: $0 dbuser" | ||
exit $E_BADARGS | ||
fi | ||
|
||
echo "I'll need your MySQL root user password next." | ||
|
||
$MYSQL -uroot -p -e "$SQL" |