Beginners 4 basic commands of database in mysql server

Today we will learn about 4 basic commands in mysql server which are related to manage the database.These 4 commands are important for any Mysql Database administrator.The post is mainly written for beginners of MySQL database administration.
All the data are saved in some database. These Databases have some name hence the basic thing is,we should know how can we create,drop(remove),show or connect to databases in MySQL server.

MySQL Server Version : 5.5.31

First login in MySQL server

MySQL root user has all privileges and it is by defualt administrator in MySQL Server.
We will do all the practical by using mysql user root. You can also replace username root with your mysql user but it must have privileges to create,drop,rename and show databases

First login into the mysql server by using below given syntax.

mysql -u username -p 

See my below reference ,how it looks after login into server.It will give mysql prompt (mysql>.Here I have login with user root)

root@debian:~# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 160
Server version: 5.5.31-0+wheezy1 (Debian)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql>

How to show databases in mysql server

To show number of databases exist in mysql server use the below given command in mysql prompt.

show databases;

Given below is the reference of my system

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| owncloud           |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

mysql>

How to create database in MySQL server

To create a database in MySQL server use the below given command

create database database-name;

Given below is the reference of my system.
Note: I used show databases; to see new database name linux in database list.

mysql> 
mysql> create database linux;
Query OK, 1 row affected (0.00 sec)

mysql> 
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| linux              |
| mysql              |
| owncloud           |
| performance_schema |
+--------------------+
5 rows in set (0.00 sec)

mysql> 

How to remove or drop database in mysql server

To drop the database in mysql server use the below given command

drop database database-name

See the below given reference of my system

mysql> drop database linux;
Query OK, 0 rows affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| owncloud           |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

mysql> 

How to connect to database or use database in MySQL server

To connect to database or use the database, follow the given below command

use database-name

Note: To know which database you are using currently,follow the given below command.

select database();


Below is the reference of above given two commands from my system

mysql> use linux;
Database changed
mysql> 
mysql> select database();
+------------+
| database() |
+------------+
| linux      |
+------------+
1 row in set (0.00 sec)

mysql> 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.