Sunday, July 13, 2008

Creating Databases in MySQL

A database in MySQL must be created by user who has permissions to create a database.

One of the easiest tools for database creation is phpMyAdmin , a tool which runs off of your web server in php. It allows you to create databases, tables, etc. If logged in as root, you can add new users (permissions) or create new tables.

Just select privileges and then add user:


For security and following the principle of least privileges and compartmentalization, we want to limit access to the database. By assigning a one-to-one relationship between users and databases, we limit the effects of an attack on our server to one database and not all of our databases. So, with the new user, we create a new database. We also generate a new password which may be generated automatically (by pressing the generate button) and copying it to the fields above. Or, we may use our own password. However, be sure to use a different password than your other databases.


You can create the database for the user at the same time by selecting the appropriate field in the "Database for user" area. For security, do not give any "Global privileges." Press ok at the bottom of the form.

Your user and database have been created with security in mind:
  • one database, one user, unique password - containment and least privileges.
  • localhost requires that any attack on that database must come from within your system.

If you don't have phpMyAdmin or other tool, here are the basic SQL commands:
CREATE USER 'flowertownDB'@'localhost' IDENTIFIED BY '***********';

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

CREATE DATABASE IF NOT EXISTS `flowertownDB` ;

GRANT ALL PRIVILEGES ON `flowertownDB` . * TO 'flowertownDB'@'localhost';

Labels: , ,

0 Comments:

Post a Comment

<< Home