Setting up the tutorial database
In this section we will create a new database, a new user, and a very simple table. MySQL has a two level directory like hierarchy for keeping databases and tables. At the root there is MySQL; under root you can only create “databases.” Database is almost like a directory, you can create “tables” under a database. Follow the steps listed below.

1. Start the mysql server (follow the CSIF MySQL tutorial).
2. Check if mysql server is running.
$ mysqladmin -u root -p status
Uptime: 434 Threads: 1 Questions: 86 Slow queries: 0 …
3. Start the mysql client. We will use the command line client to create a new database, a new user and a table in the new database.
(a) $ mysql -u root -p
Welcome to the MySQL monitor. Commands end with ; or \g.
mysql>
(b) Create a new database named ecs160tutorial.
mysql> CREATE DATABASE ecs160tutorial;
Query OK, 1 row affected (0.06 sec)
(c) Create a user with all privileges on this database. The user name will be tutorial user and the password will be 123456. Although this is NOT good practice, it will suffice.
mysql> GRANT ALL ON ecs160tutorial.* TO tutorialuser@’%’
-> IDENTIFIED BY ’123456’;
mysql> GRANT ALL ON ecs160tutorial.* TO tutorialuser@’localhost’
-> IDENTIFIED BY ’123456’;

Download pdf MySQL and Java