Skip to main content

Basic MySQL commands

In this tutorial, we will learn about some basic MySQL commands. MySQL is an open-source relational database management system that uses Structured Query Language (SQL). These commands will help you interact with the database, manipulate data and schemas, and manage the whole database system.

Getting Started

Before we start, ensure that you have MySQL installed on your machine. If you haven't done so yet, you can download it from the official MySQL website. After installation, you can access MySQL via the command line or any MySQL client.

Basic MySQL Commands

1. SHOW DATABASES

This command is used to show all the databases that are available in your MySQL server.

SHOW DATABASES;

2. USE

The USE command is utilized to select a specific database in the MySQL server.

USE database_name;

Replace database_name with the name of your database.

3. CREATE DATABASE

This command is used to create a new database.

CREATE DATABASE database_name;

4. DROP DATABASE

This command is used to delete a database.

DROP DATABASE database_name;

5. SHOW TABLES

This command is used to show all the tables in the currently selected database.

SHOW TABLES;

6. CREATE TABLE

This command is used to create a new table.

CREATE TABLE table_name(
column1 datatype,
column2 datatype,
....
);

Replace table_name with the name of your table, column with the name of your column, and datatype with the type of data you want to store.

7. DROP TABLE

This command is used to delete a table.

DROP TABLE table_name;

8. INSERT INTO

This command is used to insert new data into a table.

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

9. SELECT

This command is used to select data from a database. The data returned is stored in a result table.

SELECT column1, column2,... FROM table_name;

You can also use * to select all columns.

SELECT * FROM table_name;

10. UPDATE

This command is used to modify the existing records in a table.

UPDATE table_name SET column1 = value1, column2 = value2,... WHERE condition;

11. DELETE

This command is used to delete existing records in a table.

DELETE FROM table_name WHERE condition;

Remember to always backup your data before performing any deletion operation.

These are the basic MySQL commands that you should become familiar with when you start learning MySQL. In the upcoming tutorials, we will dive deeper into each command, learn more advanced commands, and explore various MySQL operations. Happy learning!