@@ -9,7 +9,15 @@ ${0##*/}
99 Uses the db-credentials script to start a command line mysql
1010 session with the correct host, database, user and password.
1111 Should be run from the project root folder. Passes all command
12- line arguments (except for \` -h\` ) to mysql.
12+ line arguments (except for \` --help\` ) and I/O redirection to
13+ mysql. This script can be used as a complete replacement for
14+ the normal mysql command, without having to worry about
15+ connection credentials.
16+
17+ Called without arguments, the command will log you into the
18+ default database used by the CakePHP app. Using I/O redirection,
19+ .sql files can be imported into that database as well:
20+ \` bin/db-login < my-file.sql\`
1321
1422Usage:
1523 bin/${0##*/ }
1927
2028 exit ${1:- 0} # Exit with code 0 unless an arg is passed to the method.
2129}
22- if [ " $1 " = ' -h ' ]; then
30+ if [ " $1 " = ' --help ' ]; then
2331 usage
2432fi
2533
@@ -42,9 +50,9 @@ CMD="mysql --host=${DB_HOST} ${PORT_CLAUSE} --database=${DB_DATABASE} --user=${D
4250
4351# Handle all the different ways to provide (or not provide) a password.
4452if [[ $DB_PASSWORD =~ " |'" ]]; then
45- $CMD -p" ${DB_PASSWORD} " " $@ "
53+ $CMD -p" ${DB_PASSWORD} " " $@ " < & 0
4654elif [ -n " ${DB_PASSWORD} " ]; then
47- $CMD -p$DB_PASSWORD " $@ "
55+ $CMD -p$DB_PASSWORD " $@ " < & 0
4856else
49- $CMD " $@ "
57+ $CMD " $@ " < & 0
5058fi
0 commit comments