Hide selected databases in phpMyAdmin
Posted October 21st, 2008 in MySql and PHP
A few days ago I posted how to hide the information schema in phpMyAdmin and of course using the advice in that post you can hide any database you want. The hide_db phpMyAdmin configuration option is a regular expression so you can use it to hide several databases, and this post looks at how to do this.
Open up phpMyAdmin's config.inc.php configuration file in your favourite text editor and look for the following section:
/* * First server */ $i++; /* Authentication type */ $cfg['Servers'][$i]['auth_type'] = 'cookie'; /* Server parameters */ $cfg['Servers'][$i]['host'] = 'localhost'; $cfg['Servers'][$i]['connect_type'] = 'tcp'; $cfg['Servers'][$i]['compress'] = false; /* Select mysqli if your server has it */ $cfg['Servers'][$i]['extension'] = 'mysql'; /* User for advanced features */ $cfg['Servers'][$i]['controluser'] = ''; $cfg['Servers'][$i]['controlpass'] = '';
Then add a new line that looks like this:
$cfg['Servers'][$i]['hide_db'] = 'databases go here';
In the above example, replace 'databases go here' with the regular expression to specify which databases you want to hide. Note that if you simply put something like "mysql" as the database (to hide the mysql database with all the permissions etc in it) then any database with "mysql" in the name will be hidden, if there were any.
Therefore to hide just the mysql database, you would do this:
$cfg['Servers'][$i]['hide_db'] = '^mysql$';
To hide the mysql and information_schema databases you would do this:
$cfg['Servers'][$i]['hide_db'] = '^information_schema|mysql$';
The ^ indicates the start of the string, the | means "or" and the $ indicates the end of the string. So each additional database you add would have | then the database name, e.g.:
$cfg['Servers'][$i]['hide_db'] = '^information_schema|mysql|foo$';
Please note that this will hide the databases from the user, but it doesn't stop them from being able to run queries against tables you have hidden. You would need to modify the MySQL database permissions to prevent them access to particular databases. Note also that when you do limit the databases a user has access to, phpMyAdmin won't show them in the list of databases.
Related posts:
- Hide the information schema in phpMyAdmin (Saturday, October 11th 2008)
- phpMyAdmin (Wednesday, December 10th 2003)
Recent posts:
- MySQL queries for article summaries part 2 of 2 (Tuesday, January 6th 2009)
- Aims for 2009 (Monday, January 5th 2009)
- Weekly Roundup - January 5th 2008 (Monday, January 5th 2009)
- MySQL queries for article summaries part 1 of 2 (Sunday, January 4th 2009)
- 2008 Summary of Posts (Saturday, January 3rd 2009)
- 2008 / 2009 overview (Friday, January 2nd 2009)
Subscribe to RSS Feed / Email / Bookmark / Share
Use the buttons below to subscribe to my RSS feed to be notified next time something is posted, share this post with others, or subscribe by email and have my posts sent in a daily email.
Posts are made using the following schedule (although it may vary some weeks): Mondays & Fridays = PHP; Tuesdays & Saturdays = MySQL; Wednesdays & Sundays = Javascript/jQuery; Thursdays = HTML/CSS.
