MySQL command-line client commands

This command allows us to connect with MySQL

Server with a username and passwords using below syntax.

mysql -u [username] -p;  

If you want to connect with a particular database, use this syntax:

mysql -u [username] -p [database];  

If you want to set a new password, use this syntax:

mysqladmin -u root password your_password;  

We can use the “exit” command to quit the MySQL command-line client.

We can clear the console window in Linux using the below command:

mysql> system clear;  

CREATE DATABASE IF NOT EXISTS db_name;  

If you want to change the current database with another database on which you are working, use the below syntax:

mysql> use db_name;  

We can delete a particular database along with its associated files permanently using the below syntax:

DROP DATABASE IF EXISTS db_name;  

To show all databases in the current server, use this syntax:

mysql> SHOW DATABASES;  

A table is a collection of related data stored in a row and column format within a database. We can create a new table using the below syntax. It also checks the table name, whether it already exists or not.

CREATE TABLE IF NOT EXISTS tab_name (  

  column_list (s)  

);  

to add a record into the table, which is given below:

INSERT INTO table_name ( field1, field2,…fieldN ) VALUES ( value1, value2,…valueN );  

We can delete a particular table along permanently using the below syntax:

DROP TABLE IF EXISTS tab_name;  

mysql> SHOW TABLES;