Free tutorials & notes in Hindi & English · Clean code examples 🧰 Free PDF & Image Tools →
MySQL + SQL · Lesson 32

MySQL Setup and First Commands

In this lesson: Start MySQL: create database, USE, SHOW DATABASES/TABLES and DESCRIBE — every command with output for beginners. In Hindi & English.

Your first MySQL session

Once MySQL is installed, the first thing to learn is the basic flow: create a database, select it, create a table, add data, and view it. These five commands are the foundation of everything else. Every command ends with a semicolon ;.

💡 The flow: CREATE DATABASE → USE → CREATE TABLE → INSERT → SELECT.

Create a database

CREATE DATABASE school;
Query OK, 1 row affected (0.01 sec)

This makes a new, empty database called school. You can see all databases with SHOW DATABASES;. Names should be simple and have no spaces.

Select the database

USE school;
Database changed

USE tells MySQL which database your next commands apply to. Forgetting this gives a "No database selected" error when you try to create a table.

Create a table

CREATE TABLE students (
    roll INT PRIMARY KEY,
    name VARCHAR(50),
    marks INT
);
Query OK, 0 rows affected (0.03 sec)

This creates a students table with three columns. roll is the primary key (unique id), name holds up to 50 characters, and marks is a number.

Insert a row

INSERT INTO students (roll, name, marks)
VALUES (1, 'Aman', 88);
Query OK, 1 row affected (0.01 sec)

INSERT INTO adds a row. You list the columns, then the matching values. Text values go in single quotes; numbers do not.

View the data

SELECT * FROM students;
+------+------+-------+ | roll | name | marks | +------+------+-------+ | 1 | Aman | 88 | +------+------+-------+

SELECT * shows all columns of all rows. This is how you check your data. Use SHOW TABLES; to list tables and DESCRIBE students; to see the columns.

Common mistakes

  • Forgetting the semicolon. MySQL waits for more input without ;.
  • Skipping USE. You get "No database selected".
  • No quotes on text. String values need single quotes: 'Aman'.
  • Spaces in names. Keep database and table names simple, no spaces.

Summary

  • Create a database with CREATE DATABASE, then USE it.
  • Create a table with columns and a primary key.
  • Add rows with INSERT INTO ... VALUES.
  • View data with SELECT * FROM table.
  • End every command with a semicolon.

Next, explore more commands in MySQL CLI basics, or the command groups in DDL, DML and DQL.

Frequently Asked Questions

How do I create a database in MySQL?
Use CREATE DATABASE dbname;. Then switch to it with USE dbname; before creating tables. Database and table names should be simple, without spaces.
What does the USE command do?
USE dbname; selects which database your following commands apply to. Without it, MySQL does not know where to create tables or insert data, and shows a "No database selected" error.
How do I see all databases and tables?
Use SHOW DATABASES; to list all databases and SHOW TABLES; (after USE) to list tables in the current database. DESCRIBE tablename; shows a table's columns.
Why must every SQL command end with a semicolon?
In the MySQL command line, the semicolon ; tells MySQL the command is complete and should run. Without it, MySQL waits for more input, showing a continuation prompt.
What is the order of first commands in MySQL?
Typically: CREATE DATABASE, USE it, CREATE TABLE, INSERT rows, then SELECT to view. This sequence builds up your data from scratch and lets you check the result at the end.
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 Live Code Editor

This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.
Next topicMySQL Command Line Basics Your progress: 32 / 151 (21%) · Lesson 33 / 151 Continue →

How was this lesson?

Your feedback helps us make the content better.

Write a review or suggestion (optional)

After approval, your name and city may appear publicly with your review. Please do not write your email or phone number.

▶ CodingEasily on YouTube

Learn with video lessons in easy Hindi

Featured video: RDBMS Part 3 – Class XI Commerce IT

▶ Subscribe – it’s free