Fork me on GitHub

article

Quickly View WordPress DB Credentials

December 18, 2009 | Web Design & Development

Stupid Gippy Trick #2495: The title may sound funny, and the concept a bit weird, but when you’re working on many different client servers, development and production servers, with as many different configurations, keeping track of DB credentials can get a little tiresome and time consuming.

Here’s a command line one liner to print the database credentials so that they’re easily used to manually log in to MySQL or do a database dump:

  1.  $ grep DB_ wp-config.php

Which prints out:

  1.  define('DB_NAME', 'putyourdbnamehere');
  2.  define('DB_USER', 'usernamehere');
  3.  define('DB_PASSWORD', 'yourpasswordhere');
  4.  define('DB_HOST', 'localhost');
  5.  define('DB_CHARSET', 'utf8');
  6.  define('DB_COLLATE', '');

Voila! No more switching back and forth from a credentials file or database or get the credentials, you simply use that’s already there.

Somebody more ambitious could probably make a little function that parses that output and creates a MySQL login command or mysqldump command, but right now that’s not me. 😉