Basic MySQL Interview Questions

1. What is MySQL?

Ans: MySQL is an open-source relational database management system that uses Structured Query Language (SQL). Owned by Oracle Corporation, it is compatible with multiple platforms and widely used in developing websites and web applications.

2. In which language has MySQL been written?

Ans: MySQL is primarily written in C and C++, with its SQL parser developed using Yacc (Yet Another Compiler Compiler).

3. What does ‘MySQL’ stand for?

Ans: “My” in MySQL refers to the first name of co-founder Michael Widenius’ daughter, My Widenius. “SQL” stands for Structured Query Language, a standard language used to manage and manipulate databases. SQL is also used in other database systems such as Oracle and Microsoft SQL Server.

4. What is a database?

Ans: A database is an organized collection of data stored electronically in a computer system, designed to allow efficient searching and quick retrieval of information. It is typically managed using a database management system (DBMS).

5. What are the advantages of using MySQL?

Ans: MySQL: Fast, Stable, and Reliable

MySQL is a high-performance database management system known for its speed, stability, and reliability. Its key advantages include:

  • Data Security – Recognized as one of the most secure and reliable database systems, ensuring robust protection for sensitive data.

  • Cross-Platform Flexibility – Compatible with all major operating systems, with 24/7 support and enterprise indemnification options.

  • High Performance – Engineered for demanding applications, delivering optimal speed and consistent performance.

  • On-Demand Scalability – Easily scalable and fully customizable to meet evolving business needs.

  • Enterprise-Level SQL Features – The Enterprise Edition includes advanced tools, features, and dedicated technical support for large-scale deployments.

  • Full-Text Indexing & Search – Built-in support for full-text indexing and fast, accurate search functionality.

  • Query Caching – Smart memory caching mechanisms significantly boost query processing speed.

  • Replication Support – Enables data replication across multiple servers, enhancing redundancy, availability, and load balancing.

6. What does a MySQL database contain?

Ans: A MySQL database consists of one or more tables. Each table holds multiple records (rows), and each record is made up of various columns (fields) that store specific pieces of data.

7. How to check MySQL version?

Ans: “The command mysql -V can be used to check the MySQL version on Linux.”

8. List the ways to interact with MySQL.

Ans: Users can interact with MySQL in three primary ways:

  1. Command Line Interface (CLI): By entering SQL commands directly through the terminal or command prompt.

  2. Web Interface: Using tools like phpMyAdmin or MySQL Workbench that provide a graphical interface for managing databases.

  3. Programming Languages: Through integration in languages like PHP, Python, Java, or Node.js using MySQL libraries or connectors.

9. What are MySQL Database Queries?

Ans: A query is a request made to a database to retrieve specific data or information. In MySQL, users can perform queries to obtain particular records, which are then returned as results.

10. What are the different tables in MySQL?

Ans: They are:

  • MyISAM

  • HEAP/Merge

  • InnoDB

  • ISAM

11. What are some common MySQL commands?

Ans: Some Common MySQL Commands Are:

  • CREATE – Creates a new table or database

  • INSERT – Inserts data into a table

  • JOIN – Combines rows from two or more tables based on a related column

  • DELETE – Deletes specific rows from a table

  • ALTER – Modifies the structure of a table or database

  • BACKUP – Backs up a database or table (Note: MySQL doesn’t have a direct BACKUP command; backups are typically done via mysqldump)

  • DROP – Deletes an entire database or table

  • CREATE INDEX – Adds an index to a column for faster querying

  • GRANT – Assigns privileges to users

  • TRUNCATE – Removes all rows from a table quickly

  • EXIT – Exits the MySQL command-line interface

12. How to create table using MySQL?

Ans: The following query can be used to create a table named history:

CREATE TABLE history (
author VARCHAR(128),
title VARCHAR(128),
type VARCHAR(16),
year CHAR(4)
)
ENGINE=InnoDB;

This query creates a table called history in the currently selected database.


Key Modifications:

  • Removed single quotes around column and table names (use backticks or nothing; single quotes are for string literals).

  • Improved clarity and formatting for better readability.

  • Reworded the final sentence slightly for smoother flow.

13. How to create a database in MySQL?

Ans: The CREATE DATABASE statement is used to create a new database.

14. How to insert data in MySQL?

Ans: The INSERT INTO statement in MySQL is used to add new records to a table.

There are two primary syntaxes:

1. Specify column names:

INSERT INTO table_name (column1, column2, column3, ..., columnN)
VALUES (value1, value2, value3, ..., valueN);

2. Insert values into all columns (in order):

INSERT INTO table_name
VALUES (value1, value2, value3, ..., valueN);

15. How to create an index?

Ans: MySQL supports various types of indexes, including regular INDEX, PRIMARY KEY, and FULLTEXT indexes. These indexes are created on specific columns to enhance data retrieval efficiency. Indexing optimizes search operations by either organizing the data on disk or guiding the SQL engine to the exact location of the required data.

16. How do you remove a column form a database?

Ans: Corrected Statement:

ALTER TABLE history DROP COLUMN title;

Explanation:

  • SQL keywords (ALTER TABLE, DROP COLUMN) are written in uppercase by convention.

  • Table and column names should not be enclosed in single quotes ('history' is incorrect).

  • Use straight syntax without quotes for object identifiers unless using reserved keywords or special characters.

17. How do you delete data from MySQL table?

Ans: We use the DELETE statement to remove records from a table.

The syntax is as follows:

DELETE FROM table_name
WHERE column_name = value;

18. What are numeric data types in MySQL?

Ans: MySQL supports various numeric data types to store integer, fixed-point, floating-point, and bit values. All numeric types, except BIT, can be either signed or unsigned.

Examples of Numeric Data Types:

  • INT – Standard integer

  • TINYINT – Very small integer

  • SMALLINT – Small integer

  • MEDIUMINT – Medium-sized integer

  • BIGINT – Large integer

  • DECIMAL – Fixed-point number

  • FLOAT – Single-precision floating-point number

  • DOUBLE – Double-precision floating-point number

  • BIT – Bit-field (stores binary values)

19. How can you view a database in MySQL?

Ans: The SHOW DATABASES command is used to list all the databases available on the MySQL server.

20. How to import database in MySQL?

Ans: There are two common methods to import a database or transfer data from one location to another:

  1. Using the Command Line Tool

  2. Using MySQL Workbench

21. What are string data types in MySQL?

Ans: The string data types in MySQL include:

  • CHAR

  • VARCHAR

  • BINARY

  • VARBINARY

  • TINYBLOB

  • BLOB

  • MEDIUMBLOB

  • LONGBLOB

  • TINYTEXT

  • TEXT

  • MEDIUMTEXT

  • LONGTEXT

  • ENUM

  • SET

22. What is BLOB?

Ans: BLOB stands for Binary Large Object. It is a data type used to store a variable amount of binary data, such as images, multimedia, or other large files.

23. What are temporal data types in MySQL?

Ans: MySQL Temporal Data Types

MySQL offers various temporal data types to store date, time, and combined date-time values:

  • DATE – Stores a date in the format YYYY-MM-DD (e.g., 2025-06-21)

  • TIME – Stores a time in the format HH:MM:SS (e.g., 14:30:00)

  • DATETIME – Stores both date and time in the format YYYY-MM-DD HH:MM:SS

  • TIMESTAMP – Stores a timestamp in the format YYYY-MM-DD HH:MM:SS, typically used for recording the time of an event (auto-updated on insert/update)

  • YEAR – Stores a year in YYYY or YY format (e.g., 2025 or 25)

24. How do you add users in MySQL?

Ans: The CREATE USER command, along with the necessary credentials, is used to add new users to the database.

CREATE USER 'testuser'@'localhost'IDENTIFIED BY'sample_password

  • Replaced the phrase “can be used” with “is used” for more confident wording.
  • Added @'localhost' to explicitly define the host (common in MySQL).

  • Changed 'sample password' to 'sample_password' for proper syntax (spaces in passwords require extra handling or escaping).

25. What are the Numeric Data Types in MySQL?

Ans: MySQL offers numeric data types to store integer, fixed-point, floating-point, and bit values. Except for the BIT type, all numeric types can be signed or unsigned. MySQL also supports an auto-increment attribute that enables the automatic generation of sequential values, ideal for use cases such as unique identifiers in primary key columns.

Type Name Description
TINYINT Very small integer
SMALLINT Small integer
MEDIUMINT Medium-sized integer
INT Standard integer
BIGINT Large integer
DECIMAL Fixed-point number
FLOAT Single-precision floating-point number
DOUBLE Double-precision floating-point number
BIT Bit-field (used to store bit values)

26. How do you view a database in MySQL?

Ans: One can view all the databases on the MySQL server host using the following command:

mysql> SHOW DATABASES;

Advance your career with:

  • Mock Assessments – Prepare for top company interviews with confidence

  • Real-world Coding Challenges – Practice problems based on actual industry scenarios

  • Real-Life Problems – Gain hands-on experience that mirrors job expectations

  • Detailed Reports – Get insights into your performance and areas for improvement.

27. How to Delete Data From a MySQL Table?

Ans: In MySQL, the DELETE statement is used to remove one or more records from a table. The basic syntax is:

DELETE FROM table_name
WHERE column_name = value;

The WHERE clause specifies which record(s) should be deleted. Without it, all records in the table will be removed.

28. How to create an Index in MySQL?

Ans: In MySQL, there are various types of indexes, such as regular INDEX, PRIMARY KEY, and FULLTEXT index. Indexes help improve query performance by allowing the SQL engine to quickly locate data, either by organizing it efficiently on disk or by providing direct pointers to the data location.

Example: Adding indexes to the history table

ALTER TABLE history ADD INDEX(author(10));
ALTER TABLE history ADD INDEX(title(10));
ALTER TABLE history ADD INDEX(category(5));
ALTER TABLE history ADD INDEX(year);
DESCRIBE history;

These commands create indexes on specific columns (author, title, category, and year) to optimize search operations.

29. How do you remove a column from a database?

Ans: You can delete a column from a table using the DROP keyword, like this:

ALTER TABLE classics DROP COLUMN pages;

30. How do you Insert Data Into MySQL?

Ans: The INSERT INTO statement in MySQL is used to add new records to a table. The basic syntax is:

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

If you want to insert values into all columns of the table, you can omit the column names. However, make sure that the values are provided in the exact order as the columns are defined in the table. The simplified syntax looks like this:

INSERT INTO table_name
VALUES (value1, value2, value3, ...);

30. How do you create a table using MySQL?

Ans: MySQL CREATE TABLE statement with improved formatting and optional enhancements like setting a primary key (if needed) and adding NOT NULL constraints where appropriate:

CREATE TABLE history (
author VARCHAR(128) NOT NULL,
title VARCHAR(128) NOT NULL,
type VARCHAR(16),
year CHAR(4),
PRIMARY KEY (author, title)
) ENGINE = InnoDB;

Explanation of Modifications:

  • NOT NULL constraints are added to author and title to ensure data integrity (you can remove them if nulls are allowed).

  • A composite PRIMARY KEY on author and title ensures uniqueness if each author-title combination must be distinct.

  • Proper indentation improves readability.

  • ENGINE = InnoDB remains the same, as it supports transactions and foreign keys.

31. How do you create a database in MySQL?

Ans: Use the following SQL command to create a new database named books:

CREATE DATABASE books;

32. What are some of the common MySQL commands?

Ans: 

Command Action
ALTER Modify a database or table
BACKUP Back up a table
\c Cancel current input
CREATE Create a database or table
DELETE Delete a row from a table
DESCRIBE Show the structure of a table
DROP Delete a database or table
EXIT (Ctrl+C) Exit the MySQL client
GRANT Grant user privileges
HELP (\h, \?) Display help information
INSERT Insert data into a table
LOCK Lock one or more tables
QUIT (\q) Exit the MySQL client (same as EXIT)
RENAME Rename a table
SHOW Display information about database objects
SOURCE Execute SQL commands from a file
STATUS (\s) Display the current client status
TRUNCATE Remove all rows from a table
UNLOCK Unlock previously locked tables
UPDATE Update existing data in a table
USE Select a database to work with

33. How can you interact with MySQL?

Ans: You can interact with MySQL in three main ways:

  • Using the command-line interface

  • Through a web-based interface

  • By integrating it with a programming language

34. What does SQL in MySQL stand for?

Ans: SQL in MySQL stands for Structured Query Language, a standardized language also used in other databases like Oracle and Microsoft SQL Server. It allows users to perform operations such as retrieving data using commands like:

SELECT title FROM publications WHERE author = 'J. K. Rowling';

35. What do you mean by ‘databases’?

Ans: A database is a structured collection of data stored in a computer system, organized to allow for efficient searching and quick retrieval of information.

36. What are some of the advantages of using MySQL?

Ans:

  • Flexibility: MySQL runs seamlessly on all major operating systems, offering cross-platform compatibility.

  • Performance-Oriented: MySQL is optimized for high performance, making it ideal for demanding applications.

  • Advanced SQL Features: While earlier versions lacked some capabilities, MySQL now supports enterprise-level features such as subqueries, views, stored procedures, and triggers.

  • Full-Text Indexing & Search: Enables efficient text-based searches within large datasets.

  • Query Caching: Caches SELECT queries and their results to significantly boost performance.

  • Replication: Allows one MySQL server to replicate to another, enhancing scalability, backup, and load balancing.

  • Configuration & Security: Offers robust configuration options and advanced security features, including SSL support and access control.