Creating database in mysql

Login as the mysql root user to create database:

 $ mysql -u root -p

Sample outputs:

Add a database called cars, and then enter:

mysql> CREATE DATABASE taxi1;

Now, the database is created. Use this database with use command:

 mysql> USE taxi1;

Next, create a table called drivers with name, email and id as fields:

 mysql> CREATE TABLE drivers (id INT, name VARCHAR(20), email VARCHAR(20));

To display your tables in taxi1 database, type:

mysql> SHOW TABLES;

Sample outputs:
+—————–+
| Tables_in_taxi1 |
+—————–+
| drivers         |
+—————–+
1 row in set (0.00 sec)

Finally, add a data i.e. row to table drivers using INSERT statement, run:

 mysql> INSERT INTO drivers (id,name,email) VALUES(1,”raja”,”xyz@abcde.com”);

Sample outputs:

Query OK, 1 row affected (0.00 sec)

Try to add few more rows to your table:

mysql> INSERT INTO drivers (id,name,email) VALUES(2,”kumar”,”kum@efgh.com”);

mysql> INSERT INTO drivers (id,name,email) VALUES(3,”emile”,”emile@ijkl.com”);

To display all rows i.e. data stored in drivers table, enter:

 mysql> SELECT * FROM drivers;

Sample outputs:

+——+——-+—————+
| id   | name  | email         |
+——+——-+—————+
|    1 | raja | xyz@abcde.com  |
|    2 | kumar | kum@efgh.com   |
|    3 | emile   | emile@ijkl.com |
+——+——-+—————+

3 rows in set (0.00 sec)

No comments:

Post a Comment