Shell script to open mysql with WordPress parameters

Tags:

#!/bin/bash mysqlgrep DB_NAME ~/$1wp-config.php | cut -d \' -f 4-ugrep DB_USER ~/$1wp-config.php | cut -d \' -f 4 --password=grep DB_PASS ~/$1wp-config.php | cut -d \' -f 4``

Save this as a script, such as ~/wp-mysql and do a chmod a+x on it.

Rather than lots of copying and pasting from wp-config.php, we pull the values directly from the file. Note that this assumes you have put wp-config.php in your home directory and not in public_html. If you want to use a different wp-config, pass the subdirectory name as the first argument. For example,

~/wp-mysql domains/blog.example.com/

Putting the password on the command line is not much of a security risk, as mysql replaces the actual password in the command line with 'xxxxxx' as you can see by doing ps aux while the mysql monitor is running.