Fixed mysql contrib script so it's scriptable
This commit is contained in:
@@ -14,12 +14,57 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
db="hackpad"
|
||||
mysql="mysql"
|
||||
echo "Creating database ${db}..."
|
||||
echo "create database ${db};" | ${mysql} -u root -p
|
||||
MYSQL="mysql"
|
||||
DATABASE="hackpad"
|
||||
DB_USERNAME=root
|
||||
DB_PASSWORD=
|
||||
|
||||
PROMPT=true
|
||||
|
||||
while [[ $# > 0 ]]
|
||||
do
|
||||
key="$1"
|
||||
|
||||
case $key in
|
||||
|
||||
-d|--database)
|
||||
DATABASE="$2"
|
||||
shift # past argument=value
|
||||
;;
|
||||
-u|--username)
|
||||
DB_USERNAME="$2"
|
||||
shift # past argument=value
|
||||
;;
|
||||
-p|--password)
|
||||
DB_PASSWORD="$2"
|
||||
PROMPT=false
|
||||
shift # past argument=value
|
||||
;;
|
||||
*)
|
||||
# unknown option
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
|
||||
if [ "$PROMPT" == true ]; then
|
||||
MYSQL_CMD="${MYSQL} -u ${DB_USERNAME} -p"
|
||||
else
|
||||
if [ -z "$DB_PASSWORD" ]; then
|
||||
|
||||
MYSQL_CMD="${MYSQL} -u ${DB_USERNAME}"
|
||||
else
|
||||
MYSQL_CMD="${MYSQL} -u ${DB_USERNAME} -p ${DB_PASSWORD}"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
echo "Creating database ${DATABASE}..."
|
||||
echo "create database ${DATABASE};" | echo ${MYSQL_CMD}
|
||||
|
||||
|
||||
echo "Granting priviliges..."
|
||||
echo "grant all privileges on ${db}.* to 'hackpad'@'localhost' identified by 'password';" | ${mysql} -u root -p
|
||||
echo "grant all privileges on ${DATABASE}.* to 'hackpad'@'localhost' identified by 'password';" | echo ${MYSQL_CMD}
|
||||
|
||||
echo "Success"
|
||||
|
||||
Reference in New Issue
Block a user