Creating A MySQL User And Database
This tutorial starts a case study using MySQL to provide database management services for a small company that makes specialty cookies. We highly recommend that you read our article Introduction to MySQL Databases before and sometimes during this tutorial.
Step 1 Start your MySQL system as shown in the MySQL Download tutorial. For your convenience we repeat the steps required to logon as system administrator in Figure 1.
Creating MySQL user and database tutorial Figure 1
Logging on to MySQL as the root user.
Step 2 The next step is create the cookies database. I pulled down on the scroll bar at the right margin of the window to focus on the present statement. The previous statements may be reviewed by pulling up on the scroll bar. The results are shown in Figure 2.
Creating MySQL user and database tutorial Figure 2
Creating the cookies database.
Creating MySQL user and database tutorial Figure 3
Verifying the databases.
Step 4 The next step is to create a user who will work with this database. To do so enter the following command: GRANT ALL PRIVILEGES ON cookies.* TO 'samuel'@'localhost' IDENTIFIED BY 'samuel63' WITH GRANT OPTION;
The user name is samuel whose password is samuel63. This user can do anything with this database including creating other users. The results are shown in Figure 4.
Creating MySQL user and database tutorial Figure 4
Creating a user for the cookies database.
Step 5 Press Ctrl-C to return to the command line. Then login as samuel whose password is samuel63, verify his databases, and activate the cookies database. Note that he does not have access to the mysql database which is an administrative database. The results are shown in Figure 5.
Creating MySQL user and database tutorial Figure 5
Samuel connects to and verifies his database.
Exercises. You are going to do your own case study. Just a suggestion, the first time through don't make it much more complicated than this one. The next time through the sky is the limit. You may even want to go to MySQL5. And don't forget your user name and password.