Separate MySQL databases environments

Now this may be common practice for some of you all, but not all.

I’d recommend the (security) practice of having separate databases for your different environments; e.g. development, testing and production. Say for a given user ‘kzhiwei’, I should have up to three databases available for use:

kzhiwei_development
kzhiwei_production
kzhiwei_testing

PHPMyAdmin provides excellent support for this function by means of its database selector dropdown, it displays databases the logged in user has access to like:

kzhiwei
|_development (3)
|_production (3)
|_testing (3)

The following is MySQL syntax with the following points:

  1. localhost-only access is provided
  2. usage of the MySQL server, sans access to other databases
  3. wildcard access to ALL databases that are named like “kzhiwei_”
CREATE USER 'kzhiwei'@ 'localhost' IDENTIFIED BY 'password';

GRANT USAGE ON * . * TO 'kzhiwei'@ 'localhost' IDENTIFIED BY 'password' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;

GRANT ALL PRIVILEGES ON `kzhiwei_%` . * TO 'kzhiwei'@ 'localhost';
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s