Mysql cmd

Education Programming
Listen to this article

To open MySQL

mysql -uroot -proot

To show all the Database

show databases;

Creating a Database:

CREATE DATABASE <mydatabase>;

Example: Creating the Database “student”

Delete a database

Drop database <databasename>;

Example: Deleting the Database “student”

Use a database

USE <databasename>;

Example: Using the database “student”

Check current database

select database();

Example: Using the database “student” and checking the current database name.

Create table

CREATE TABLE tablename(
    column_name data_type;
    column_name data_type;
);

Show tables in MySql

I have 2 tables on the database named “students”. One is students and another is studentsdemo.

Description of a table on the database

There are 2 commands for a description of the table on the database. You can use any of them to show a description for the table.

desc <table_name>;
show columns from <table_name>;

Here I have shown the description of the table name “students”.

Insert data in Table

INSERT INTO table_name(column1, column2,column3, ....)
            VALUES(value1, value2,value3, ....)

If you are adding values for all the columns of the table, you do not need to specify the column names in the SQL query. However, make sure the order of the values is in the same order as the columns in the table. Here, the INSERT INTO syntax would be as follows:

INSERT INTO table_name
VALUES (value1, value2, value3, ...);

Select from Table

SELECT * FROM <tablename>;

I am selecting all data from table “students”.

rubina
Author: rubina