Mysql Interview Questions
Mysql Interview Questions
1) What is MySQL?
Formerly MySQL was initially owned by a for-profit firm MySQL AB, then Sun Microsystems bought it and then
Oracle bought Sun Microsystems, so Oracle currently owns MySQL.
What is Lamp?
Lamp is a platform used for web development. Lamp uses Linux, Apache, MySQL, and PHP as an operating
system, web server, database & object-oriented scripting language respectively. And hence abbreviated as
LAMP.
MySQL is written in C and C++, and its SQL parser is written in yacc.
Flexible structure
High performance
Drivers
⇧
Graphical Tools
https://www.javatpoint.com/mysql-interview-questions 1/11
1/22/2019 MySql Interview Questions - javatpoint
JSON Support
Geo-Spatial Support
SQL is known as the standard query language. It is used to interact with the database like MySQL. MySQL is a
database that stores various types of data and keeps it safe.
A PHP script is required to store and retrieve the values inside the database.
SQL is used for the creation of database management systems whereas MySQL is used to enable data
handling, storing, deleting and modifying data
There is a major difference between a database and a table. The differences are as follows:
Tables are a way to represent the division of data in a database while the database is a collection of
tables and data.
Tables are used to group the data in relation with each other and create a dataset. This dataset will be
used in the database. The data which are stored in the table in any form is a part of the database, but
the reverse is not true.
A database is a collection of organized data and also features which are used to access them, whereas
table is a collection of rows and columns which are used to store the data.
First of all MYSQL server is free to use for developers and a small fee for enterprises.
The community of MySQL is tremendous and supportive hence any help regarding MySQL is resolved as soon
as possible.
MySQL has very stable versions available, as MySQL has been in the market since a long time so all bugs
arising in the previous builds have been continuously removed and a very stable version is provided after
every update.
The MySQL database server is very fast, reliable and easy to use. You can easily use and modify the software.
MySQL software can be downloaded free of cost from the internet.
https://www.javatpoint.com/mysql-interview-questions 2/11
1/22/2019 MySql Interview Questions - javatpoint
There are many tables that remain present by default. But, MyISAM is the default database engine used in
MySQL. There are five types of tables that are present:
MyISAM
Heap
Merge
INNO DB
ISAM
CHAR column length is fixed to the length that is declared while creating a table. The length value
ranges from 1 and 255.
When CHAR values are stored when they are right-padded using spaces to a specific length. Trailing
spaces are removed when CHAR values are retrieved.
CHAR uses static memory allocation whereas VARCHAR uses dynamic memory allocation.
It is not possible to use Where command with TRUNCATE but you can use it with DELETE command.
TRUNCATE cannot be used with indexed views whereas DELETE can be used with indexed views.
The DELETE command is used to delete data from a table. It only deletes the rows of data from the table
while, truncate is very dangerous command and should be used carefully because it deletes every row
permanently from a table.
1. Before Insert
2. After Insert
3. Before Update
4. After Update
5. Before Delete
6. After Delete
https://www.javatpoint.com/mysql-interview-questions 3/11
1/22/2019 MySql Interview Questions - javatpoint
Tables that are present in memory is known as HEAP tables. When you create a heap table in MySQL, you
should need to specify the TYPE as HEAP. These tables are commonly known as memory tables. They are used
for high-speed storage on a temporary basis. They do not allow BLOB or TEXT fields.
BLOB is an acronym stands for a large binary object. It is used to hold a variable amount of data.
1. TINYBLOB
2. BLOB
3. MEDIUMBLOB
4. LONGBLOB
The differences among all these are the maximum length of values they can hold.
TEXT is a case-insensitive BLOB. TEXT values are non-binary strings (character string). They have a character
set, and values are stored, and compared based on the collation of the character set.
1. TINYTEXT
2. TEXT
3. MEDIUMTEXT
4. LONGTEXT
14) What is the difference between heap table and temporary table?
Heap tables:
Heap tables are found in memory. They are used for high-speed storage on a temporary basis. They do not
allow BLOB or TEXT fields.
Temporary tables:
The temporary tables are used to keep the transient data. Sometimes it is beneficial in cases to hold
temporary data. The Temporary table is deleted after the current client session terminates.
Main differences:
The heap tables are shared among clients while temporary tables are not shared.
Heap tables are just another storage engine, while for temporary tables you need a special privilege (create
temporary table).
FLOAT stores floating point numbers with accuracy up to 8 places and allocates 4 bytes, on the other hand
DOUBLE stores floating point numbers with accuracy up to 18 places and allocates 8 bytes. ⇧
https://www.javatpoint.com/mysql-interview-questions 4/11
1/22/2019 MySql Interview Questions - javatpoint
1. MySQL is a free, fast, reliable, open source relational database while Oracle is expensive, although they
have provided Oracle free edition to attract MySQL users.
2. MySQL uses only just under 1 MB of RAM on your laptop while Oracle 9i installation uses 128 MB.
3. MySQL is great for database enabled websites while Oracle is made for enterprises.
4. MySQL is portable.
2. It does not support COMMIT and STORED PROCEDURES functions version less than 5.0.
3. The maximum no. of character CHAR data type can hold is 255 character while VARCHAR can hold up
to 4000 character.
5. CHAR uses static memory allocation while VARCHAR uses dynamic memory allocation.
Mysql_connect:
2. Every time you need to open and close database connection, depending on the request.
Mysql_pconnect:
1. In Mysql_pconnect, "p" stands for persistent connection so it opens the persistent connection.
3. It is more useful if your site has more traffic because there is no need to open and close connection
frequently and every time when page is loaded.
The "i_am_a_dummy flag" enables MySQL engine to refuse any UPDATE or DELETE statement to execute if
the WHERE clause is not present. Hence it can save the programmer from deleting the entire table my mistake
if he does not use WHERE clause.
https://www.javatpoint.com/mysql-interview-questions 5/11
1/22/2019 MySql Interview Questions - javatpoint
SELECT CURRENT_DATE();
24) What is the difference between Unix timestamps and MySQL timestamps?
Actually both Unix timestamp and MySQL timestamp are stored as 32-bit integers but MySQL timestamp is
represented in readable format of YYYY-MM-DD HH:MM:SS format.
25) How to display Nth highest salary from a table in a MySQL query?
REGEXP is a pattern match using a regular expression. A Regular expression is a powerful way of specifying a
pattern for a sophisticated search.
Basically it is a special text string for describing a search pattern. To understand it better you can think of a
situation of daily life when you search for .txt files to list all text files in the file manager. The regex equivalent
for .txt will be .*\.txt.
NOW() command is used to show current year, month, date with hours, minutes and seconds while
CURRENT_DATE() shows the current year with month and date only.
https://www.javatpoint.com/mysql-interview-questions 6/11
1/22/2019 MySql Interview Questions - javatpoint
SELECT NOW();
SELECT CURRENT_DATE();
SAVEPOINT is a statement in MySQL which is used to set a named transaction save point with a name of
identifier.
SQLyog program is the most popular GUI tool for admin. It is the most popular MySQL manager and admin
tool. It combines the features of MySQL administrator, phpMyadmin and others MySQL front ends and MySQL
GUI tools.
It is easy to back up data with phpMyAdmin. Select the database you want to backup by clicking the database
name in the left-hand navigation bar. Then click the export button and make sure that all tables are
highlighted that you want to back up. Then specify the option you want under export and save the output.
The =, <>, <=, <, >=, >, <<, >>, < = >, AND, OR or LIKE operator are the comparison operators in
MySQL. These operators are generally used with SELECT statement.
38) Write a query to select all teams that won either 1, 3, 5 or 7 games.
https://www.javatpoint.com/mysql-interview-questions 7/11
1/22/2019 MySql Interview Questions - javatpoint
ENUMs are string objects, by defining ENUMs we allow the end user to give correct input as in case the user
provides an input which is not part of the ENUM defined data then the query won't execute and an error
message will be displayed which says "Wrong Query". For instance suppose we want to take the gender of the
user as an input so we specify ENUM('male', 'female', 'other') and hence whenever the user tries to input any
string any other than these three it results in an error.
ENUMs are used to limit the possible values that go in the table:
For example:
CREATE TABLE months (month ENUM 'January', 'February', 'March'); INSERT months VALUES ('April').
MyISAM follows a conservative approach to disk space management and stores each MyISAM table in a
separate file, which can be further compresses, if required. On the other hand, InnoDB stores the tables in
tablespace. Its further optimization is difficult.
Mysql_fetch_object is used to retrieve the result from the database as objects while mysql_fetch_array
returns result as an array. This will allow access to the data by the field names.
For example:
Using mysql_fetch_row($result) where $result is the result resource returned from a successful query
executed using the mysql_query() function.
Example:
Mysql_connect() is used to open a new connection to the database while mysql_pconnect() is used to open a
persistent connection to the database. It specifies that each time the page is loaded mysql_pconnect() does
not open the database.
⇧
https://www.javatpoint.com/mysql-interview-questions 8/11
1/22/2019 MySql Interview Questions - javatpoint
Mysql_close() cannot be used to close the persistent connection. Though it can be used to close connection
opened by mysql_connect().
MySQL data directory is a place where MySQL stores its data. Each subdirectory under this data dictionary
represents a MySQL database. By default the information managed my MySQL = server mysqld is stored in
data directory.
The default location of MySQL data directory in windows is C:\mysql\data or C:\Program Files\MySQL\MySQL
Server 5.0 \data.
In MySQL, regular expressions are used in queries for searching a pattern in a string.
[abc] matches a or b or z
| separates strings
"." Can be used to match any single character. "|" can be used to match either of the two strings
REGEXP can be used to match the input characters with the database.
Example:
The following statement retrieves all rows where column employee_name contains the text 1000
(example salary):
Select employee_name
From employee
Where employee_name REGEXP '1000'
Order by employee_name
In MySQL, the "i-am-a-dummy" flag makes the MySQL engine to deny the UPDATE and DELETE commands
unless the WHERE clause is present.
50) Which command is used to view the content of the table in MySQL?
The SELECT command is used to view the content of the table in MySQL.
https://www.javatpoint.com/mysql-interview-questions 9/11
1/22/2019 MySql Interview Questions - javatpoint
An ACL is a list of permissions which are associated with an object. MySQL keeps the Access Control Lists
cached in memory and whenever the user tries to authenticate or execute a command, MySQL checks the
permission required for the object and if the permissions are available then execution completes successfully.
InnoDB is a storage database for SQL. The ACID-transactions are also provided in addition InnoDB also
includes support for the foreign key. Initially owned by InnobaseOY now belongs to Oracle Corporation after it
acquired the latter since 2005.
It is a system for file management developed by IBM which allows records to access sequentially or even
randomly.
mysql;
mysql mysql.out;
Federated tables are tables which points to the tables located on other databases on some other server.
56. What is the difference between primary key and candidate key?
To identify each row of a table, a primary key is used. For a table, there exists only one primary key.
A candidate key is a column or a set of columns which can be used to uniquely identify any record in the
database without having to reference any other data.
PHP Driver
JDBC Driver
ODBC Driver
C WRAPPER
PYTHON Driver
PERL Driver
RUBY Driver
CAP11PHP Driver
Ado.net5.mxz
Majorly SQL commands can be divided into three categories i.e. DDL, DML & DCL. Data Definition Language
(DDL) deals with all the database schemas, and it defines how the data should reside in the database.
Commands like CreateTABLE and ALTER TABLE are part of DDL.
⇧
https://www.javatpoint.com/mysql-interview-questions 10/11
1/22/2019 MySql Interview Questions - javatpoint
Data Manipulative Language (DML) deals with operations and manipulations on the data the commands in
DML are Insert, Select etc.
Data Control Languages (DCL) are related to the Grant and permissions. In short, the authorization to access
any part of database is defined by these.
Learn more
https://www.javatpoint.com/mysql-interview-questions 11/11