Managing the Database

Creating Users

To create users above and beyond the default privileged root user, issue the grant command. The grant command uses this syntax:
GRANT PRIVILEGES ON DATABASE.OBJECTS TO'USER'@'HOST' IDENTIFIED BY 'PASSWORD';

For example:
GRANT ALL PRIVILEGES ON *.* TO 'michele'@'localhost' IDENTIFIED BY 'secret';

This creates the user michele who can access anything locally. To change to the michele user, at the mysql command prompt, type:
exit

Then start MySQL from the command line with the new username and password. The syntax for specifying the username and password when starting MySQL is:
mysql -h hostname -u username -ppassword

If you don't want users to access tables other than their own, replace * with the name of the user's database, like this:
GRANT ALL PRIVILEGES ON `store`.* TO 'michele'@'localhost' IDENTIFIED BY 'secret';

You'll need to run the above line as root or as someone with permission. In the above code, the word store correlates to the database name to which privileges are assigned, which you'll create in the next section.

8.2.2. Creating a MySQL Database

You're going to create a database called store. The create database command works like this:
CREATE DATABASE `store`;

If this works, you'll get a result like this one:
Query OK, 1 row affected 0.03 sec
 
 
To start using this database, type:
USE `store`;
You will get the result:
Database changed.
Assuming you've done everything correctly, you'll be set up with new data and selected it for use. Creating tables is an important concept, so that's where we're headed!.


To rename a table, use ALTER TABLE table RENAME newtable. In this example, we are renaming the table from books to publications.
ALTER TABLE `books` RENAME `publications`;