How do you create a database, a table and see data in MySQL?
BeginnerHands-onMySQL
Answer
Short answer
Use SQL commands: CREATE DATABASE, USE, CREATE TABLE, INSERT INTO and SELECT. To look around, use SHOW DATABASES, SHOW TABLES and DESCRIBE <table>.
Step by step
-- 1. See what exists
SHOW DATABASES;
-- 2. Create a database and switch to it
CREATE DATABASE shop;
USE shop;
-- 3. Create a table
CREATE TABLE customers (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(150) UNIQUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- 4. See tables and the table structure
SHOW TABLES;
DESCRIBE customers;
-- 5. Add data
INSERT INTO customers (name, email) VALUES
('Aditya', '[email protected]'),
('Priya', '[email protected]');
-- 6. Read data
SELECT * FROM customers;
SELECT name, email FROM customers WHERE id = 1;
-- 7. Change and remove data
UPDATE customers SET email = '[email protected]' WHERE id = 2;
DELETE FROM customers WHERE id = 2;
Example output of SELECT * FROM customers;:
+----+--------+--------------------+---------------------+
| id | name | email | created_at |
+----+--------+--------------------+---------------------+
| 1 | Aditya | [email protected] | 2026-11-26 10:15:02 |
+----+--------+--------------------+---------------------+
Careful: UPDATE and DELETE without a WHERE change every row. Always write the WHERE first.
What to say in the interview
"I create a database with CREATE DATABASE, switch with USE, create tables with CREATE TABLE and check them with SHOW TABLES and DESCRIBE. Data goes in with INSERT and comes out with SELECT, filtered by WHERE. As a DevOps engineer I mostly use this to verify an app's tables exist after a migration, check data during troubleshooting, or create databases and users for new services."
Follow-up questions you may get
- How do you run a SQL file?
mysql -u root -p shop < schema.sql. - How do you see table sizes? Query
information_schema.tablesfordata_lengthandindex_length.
More on MySQL
How do you set up MySQL and log in to it?BeginnerHow do you create a MySQL user for an application and give it permissions?BeginnerHow do you back up and restore a MySQL database?BeginnerWhat is a relational database?BeginnerWhat is the difference between a database, a table, a row and a column?BeginnerHow do you check whether MySQL is running and which port it listens on?Beginner