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 ;.
Create a database
CREATE DATABASE school;
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;
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
);
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);
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;
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, thenUSEit. - 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?
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?
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?
; tells MySQL the command is complete and should run. Without it, MySQL waits for more input, showing a continuation prompt.