Last active
December 2, 2015 13:21
-
-
Save AV4TAr/f6cd7f369c7541bcee44 to your computer and use it in GitHub Desktop.
Script that reads php configuration file (that returns an array) and connects to a mysql database.
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
To use mysql client on staging, devs need to ssh to the server, then "cat" the configuration file of the application to get the username / password / host. | |
The idea of this script is to read the configuration from the php application and use that information to connect to mysql using the mysql client in 1 command. |
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
<?php | |
return [ | |
'db_name' => 'application', | |
'db_user' => 'root', | |
'db_password' => 'root', | |
'db_host' => '127.0.0.1' | |
]; |
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
# | |
# Aid script to connect to mysql easly in different environments. | |
# It reads the application configuration file and uses it to connect to mysql. | |
# | |
sqluname=$(php -r '$var = include("config.php"); echo $var["db_user"];') | |
sqlpasswd=$(php -r '$var = include("config.php"); echo $var["db_password"];') | |
dbname=$(php -r '$var = include("config.php"); echo $var["db_name"];') | |
sqlhost=$(php -r '$var = include("config.php"); echo $var["db_host"];') | |
if [ -n "$sqlpasswd" ]; then | |
/usr/bin/mysql -h$sqlhost -u $sqluname -p$sqlpasswd $dbname | |
else | |
/usr/bin/mysql -h$sqlhost -u $sqluname $dbname | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment