The process of creating a database is the same for most operating systems. When something cannot
be done in a particular operating system, I will make note of that fact.
You should have changed your root password for the MySQL database system. To use the
mysqladmin command and to start the mysql monitor, you will need to enter this password. For the
sake of brevity, I have left that argument (-p) off my commands.
- Open a terminal.
- Change the directory to the mysql directory. If you created a symbolic link, you
can enter - cd mysql
If you did not create a symbolic link, you will have to enter the full path, as shown in the
following:
cd /usr/local/mysql
(assuming MySQL was installed to this default directory)
Note Symbolic links are generally used as shortcuts. They can take a long path
name and condense it into one word, making it convenient for the user to
use.
- Ensure the mysqld daemon is running. To do this, enter the following:
- bin/mysqladmin ping
- After you are sure the monitor is running, start the mysql monitor by entering the
following from the command line: - bin/mysql
- At the monitor prompt, type the following:
- CREATE DATABASE sample_db;
Be sure to type it exactly as it appears. Remember that it is necessary to end the line with a semicolon
or a \g.
Your results should be similar to those in Figure 4.1.
Figure 4.1 Results of a successful database creation.
The mysql monitor is not case sensitive when it comes to SQL commands. Thus, the following
commands are all the same:
Create Database sample_db;
CrEaTe DaTaBaSe sample_db;
create database sample_db;
These commands will all create the same database named sample_db. It is a popular convention to
capitalize all SQL commands—this book will follow that convention. An important point to remember is
that capitalization does matter when it comes to objects within your database. For example,
sample_db is not the same as Sample_DB.