FullStackFSCCafé
 
 
Sign in with GoogleSign in with Google. Opens in new tab
Kill Your Tech Interview
3877 Full-Stack, Algorithms & System Design Interview Questions
Answered To Get Your Next Six-Figure Job Offer
      
🤖 Having Machine Learning & DS Interview? Check  MLStack.Cafe - 1704 Data Science & ML Interview Questions & Answers!Having ML & DS Interview? Check 🤖 MLStack.Cafe - 1704 ML & DS Interview Questions and Answers

29 Advanced MySQL Interview Questions Developers Must Know Before Tech Interview

MySQL has emerged as the most popular SQL-based RDBMS in 2019 with almost 40% of users opting for this platform. It is widely used as a stand-alone database solution as well as in combination with other solutions such as MongoDB and PostgreSQL. If you are planning a career in the database administration or development fields, it is almost a certainty that you will be working with MySQL systems in the near future. Follow along and check 27 most popular MySQL Interview Questions experience developers must know and refresh before next technical interview.

Q1: 
Describe BLOB in MySQL. What is it used for?

Answer

BLOB or Binary Large Object can be used to store binary data in MySQL. Sometimes binary data like images need to be stored in SQL databases. For example you might want to store user photos along with other user details in the database table. Binary data of the user photo can be saved as a BLOB. By using BLOB, we will not require separate storage for images. BLOB helps in removing complexity and providing portability in such cases.


Having Tech or Coding Interview? Check 👉 60 MySQL Interview Questions

Q2: 
How are VARCHAR and CHAR different. Talk about cases where you will use one over other.

Answer

Both CHAR and VARCHAR data types store characters up to specified length.

  1. CHAR stores characters of fixed length while VARCHAR can store characters of variable length.
  2. Storage and retrieval of data is different in CHAR and VARCHAR.
  3. CHAR internally takes fixed space, and if stored character length is small, it is padded by trailing space characters. VARCHAR has 1 or 2 byte prefix along with stored characters.
  4. CHAR has slightly better performance.
  5. CHAR has memory allocation equivalent to the maximum size specified while VARCHAR has variable length memory allocation.

Having Tech or Coding Interview? Check 👉 60 MySQL Interview Questions

Q3: 
What is self referencing foreign key? Give an example.

Answer

A foreign key which is stored in a table itself is called to be self referencing foreign key.

For example consider an Employee database table. It has employee_id as primary key as well as a manager_id which is employee_id of his manager. If we create a foreign key constraint, as a manager is also an employee, manager_id will reference to empolyee_id in the same table. The Employee table with self referencing foreign key manager_id can be created using below statement.

CREATE TABLE `Employee`( 
`name` VARCHAR(25) NOT NULL, 
`employee_id` CHAR(9) NOT NULL, 
`manager_id` CHAR(9) NOT NULL, 
`salary` decimal(10,2) NULL,  
PRIMARY KEY(`employee_id`),
FOREIGN KEY (manager_id) REFERENCES employee(employee_id) ON DELETE CASCADE
);

Having Tech or Coding Interview? Check 👉 60 MySQL Interview Questions

Q4: 
What is the difference between Data Definition Language (DDL) and Data Manipulation Language (DML)?

Answer
  • Data definition language (DDL) commands are the commands which are used to define the database. CREATE, ALTER, DROP and TRUNCATE are some common DDL commands.

  • Data manipulation language (DML) commands are commands which are used for manipulation or modification of data. INSERT, UPDATE and DELETE are some common DML commands.


Having Tech or Coding Interview? Check 👉 60 MySQL Interview Questions

Q5: 
What is the difference between TRUNCATE and DELETE?

Answer
  • DELETE is a Data Manipulation Language(DML) command. It can be used for deleting some specified rows from a table. DELETE command can be used with WHERE clause.

  • TRUNCATE is a Data Definition Language(DDL) command. It deletes all the records of a particular table. TRUNCATE command is faster in comparison to DELETE. While DELETE command can be rolled back, TRUNCATE can not be rolled back in MySQL.


Having Tech or Coding Interview? Check 👉 60 MySQL Interview Questions

Q6: 
Both TIMESTAMP and DATETIME are used to store data and time. Explain difference between them and when should one be used?

Answer

Both TIMESTAMP and DATETIME store date time in YYYY-MM-DD HH:MM:SS format. While DATETIME stores provided date time, TIMESTAMP first converts provided time to UTC while storing and then again converts it back to server time zone upon retrieval. So if you need to serve different users in different countries using same time data, TIMESTAMP facilitates it. DATETIME simply stores provided date time without making any time zone related conversion.


Having Tech or Coding Interview? Check 👉 60 MySQL Interview Questions

Q7: 
Explain GRANT command in MySQL

Answer

When a new MySQL user is created, he requires certain privileges to perform various database operations. GRANT command grants certain privileges to the user. For example below statement grants permission to run SELECT and INSERT on TABLE customertable to user username@localhost.

GRANT SELECT, INSERT ON customertable TO 'username'@'localhost'

Having Tech or Coding Interview? Check 👉 60 MySQL Interview Questions
Source: chartio.com

Q8: 
Explain the use of FEDERATED tables in MySQL

Answer

FEDERATED tables are tables through which MySQL provides a way to access database tables located in remote database servers. Actual physical data resides in remote machine but the table can be accessed like a local table. To use a federated table ENGINE=FEDERATED and a connection string containing user, remote hostname, port, schema and table name are provided in CREATE TABLE command something like below.

CREATE TABLE table_fed (
 ... 
)
ENGINE=FEDERATED
CONNECTION='mysql://user@remote_hostname:port/federated_schema/table';

Having Tech or Coding Interview? Check 👉 60 MySQL Interview Questions
Source: dev.mysql.com
🤖 Having Machine Learning & DS Interview? Check  MLStack.Cafe - 1704 Data Science & ML Interview Questions & Answers!Having ML & DS Interview? Check 🤖 MLStack.Cafe - 1704 ML & DS Interview Questions and Answers

Q9: 
How can ENUM be used in MySQL. Give an example.

Answer

ENUM can be used to set a column as enum type. ENUM in MySQL is string object which can take one of the permitted value. In example below, country column can have one of the three values provided:

CREATE TABLE `Student`(
`rollnumber` INT NOT NULL, 
`name` VARCHAR(25) NOT NULL, 
`country` ENUM('USA', 'UK', 'Australia'), 
PRIMARY KEY(`rollnumber`));

Consider:

INSERT INTO `Student` values('6', 'John', 'USA');

Having Tech or Coding Interview? Check 👉 60 MySQL Interview Questions
Source: codeburst.io

Q10: 
What are different TEXT data types in MySQL. What is difference between TEXT and VARCHAR?

Answer

Different text data types in MySQL include:

  • TINYTEXT,
  • TEXT,
  • MEDIUMTEXT and
  • LONGTEXT.

These data types have different maximum size. While TINYTEXT can hold string up to 255 characters, TEXT can hold up to 65,535 characters, MEDIUMTEXT can hold up to 16,777,215 characters and LONGTEXT can hold up to 4,294,967,295 characters.

VARCHAR is also a variable text data type with some difference. VARCHAR is stored inline in the database table while TEXT data types are stored elsewhere in storage with its pointer stored in the table. A prefix length is must for creating index on TEXT data types. TEXT columns do not support default values unlike VARCHAR.


Having Tech or Coding Interview? Check 👉 60 MySQL Interview Questions

Q11: 
What different stored objects are supported in MySQL?

Answer

Different stored objects in MySQL include VIEW, STORED PROCEDURE, STORED FUNCTION, TRIGGER, EVENT.

  • VIEW - It is a virtual table based on a result set of a database query.
  • STORED PROCEDURE - It is a procedure stored in database which can be called using CALL statement. Stored procedure does not return a value.
  • STORED FUNCTION - It is like function calls which can contain logic. It returns a single value and can be called from another statement.
  • TRIGGER - Trigger is program which is associated with a database table which can be invoked before or after insert, delete or update operations.
  • EVENT - Event is used to run a program or set of commands at defined schedule.

Having Tech or Coding Interview? Check 👉 60 MySQL Interview Questions
Source: dev.mysql.com

Q12: 
What is Stored Function in MySQL. How are they different from Stored Procedure?

Answer

Stored function is a stored complex logic which can be executed like a function call from any other statement. It returns a single value. It can be used to store business logic and formulas in database. Stored functions can even run SELECT command or table manipulation commands like INSERT and UPDATE.

The most general difference between procedures and functions is that they are invoked differently and for different purposes:

  1. A procedure does not return a value. Instead, it is invoked with a CALL statement to perform an operation such as modifying a table or processing retrieved records.
  2. A function is invoked within an expression and returns a single value directly to the caller to be used in the expression.
  3. You cannot invoke a function with a CALL statement, nor can you invoke a procedure in an expression.

e.g. SELECT get_foo(myColumn) FROM mytable is not valid if get_foo() is a procedure, but you can do that if get_foo() is a function. The price is that functions have more limitations than a procedure.

CREATE PROCEDURE proc_name ([parameters])
 [characteristics]
 routine_body


CREATE FUNCTION func_name ([parameters])
 RETURNS data_type       // diffrent
 [characteristics]
 routine_body

Having Tech or Coding Interview? Check 👉 60 MySQL Interview Questions

Q13: 
What is AUTO INCREMENT in MySQL? Explain with an example.

Answer
  • AUTO INCREMENT in MySQL is used to automatically assign next unique integer value to a particular column.

  • AUTO INCREMENT can be used to generate unique id for each inserted row without assigning a value to it. In MySQL, only columns which keep unique values like column with UNIQUE CONSTRAINT or PRIMARY KEY can be marked for AUTO INCREMENT. A table can have only one column marked for AUTO INCREMENT.

Code below can be used to mark studentid in Student table to auto increment. On adding a new Student without providing studentid, a unique student id with next available value is generated and assigned to the row.

CREATE TABLE `student`(`studentid` INT NOT NULL AUTO_INCREMENT,  `name` VARCHAR(25) NOT NULL, PRIMARY KEY(`studentid`));

Having Tech or Coding Interview? Check 👉 60 MySQL Interview Questions

Q14: 
What is difference between BLOB and TEXT in MySQL?

Answer
  • BLOB data types are designed to store binary data like picture or video in database.
  • TEXT data types are designed to store large text data.

BLOB stores binary byte string while TEXT stores character string. Although BLOB can be used for storing text data, TEXT data types support sorting and comparison around text which is not supported by BLOB.

There are four TEXT data types including TINYTEXT, TEXT, MEDIUMTEXT and LONGTEXT which can hold up to 255 characters, 65,535 characters, 16,777,215 characters and 4,294,967,295 characters respectively. Similarly four related BLOB types including TINYBLOB, BLOB, MEDIUMBLOB and LONGBLOB can hold up to 255 bytes, 65,535 bytes, 16,777,215 bytes and 4,294,967,295 bytes respectively.


Having Tech or Coding Interview? Check 👉 60 MySQL Interview Questions

Q15: 
What is the difference between commands create database and create schema in MySQL?

Answer

Terms database and schema are synonymous in MySQL. Some other enterprise level databases like Oracle and Microsoft SQL server make distinction between database and schema. A MySQL developer can interchangeably use both the terms. For example a database called test can be created by using either of the CREATE statements below.

    CREATE DATABASE test;
    CREATE SCHEMA test;

Having Tech or Coding Interview? Check 👉 60 MySQL Interview Questions
🤖 Having Machine Learning & DS Interview? Check  MLStack.Cafe - 1704 Data Science & ML Interview Questions & Answers!Having ML & DS Interview? Check 🤖 MLStack.Cafe - 1704 ML & DS Interview Questions and Answers

Q16: 
What is the use of DELIMETER command in MySQL?

Answer

MySQL workbench or MySQL client use ; as delimiter to separate different statements. DELIMITER command can be used to change delimiter in MySQL from ; to something else. It is used while writing trigger and stored procedures in MySQL. Command below make // as delimiter.

DELIMITER //

For example in a stored procedure, ";" is part of the actual stored procedure and not a delimiter. So while writing a stored procedure, we can make something else like // as delimiter and afterward revert it back by calling below command.

DELIMITER ;

Having Tech or Coding Interview? Check 👉 60 MySQL Interview Questions

Q17: 
A multiple column index is created over firstName, lastName, city columns of a Customer table. Will this index be used for SELECT queries based on only first_name, only last_name or only city values?

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe

Q18: 
Compare MySQL and PostgresSQL

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe

Q19: 
Provide an example of UPSERT logic using MySQL

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe

Q20: 
What are differences between MyISAM and InnoDB database engines commonly used in MySQL?

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe

Q21: 
What are some major differences between MySQL and Oracle database?

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe

Q22: 
What does OPTIMIZE TABLE command do in MySQL?

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe
🤖 Having Machine Learning & DS Interview? Check  MLStack.Cafe - 1704 Data Science & ML Interview Questions & Answers!Having ML & DS Interview? Check 🤖 MLStack.Cafe - 1704 ML & DS Interview Questions and Answers

Q23: 
What is database engine or storage engine? Mention few storage engines supported by MySQL and their use.

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe

Q24: 
What is autocommit in MySQL? Can you run a transaction without disabling autocommit?

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe

Q25: 
What is cursor used in MySQL? What are properties of MySQL cursor?

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe

Q26: 
Which partitioning types does MySQL support?

Answer
Join FullStack.Cafe to open this Answer. It's Free!
Sign in with GoogleSign in with Google. Opens in new tab
Join 120k+ Developer Who Trust FullStack.Cafe

Q27: 
How many tables can a trigger associate to in MySQL? Can a trigger be associated to a view?

Answer
Unlock FullStack.Cafe to open all answers and get your next figure job offer!
Share this blog post to open Expert question!

Q28: 
What is difference between horizontal and vertical partitioning? Does MySQL support both horizontal and vertical partitioning?

Answer
Unlock FullStack.Cafe to open all answers and get your next figure job offer!
Share this blog post to open Expert question!

Q29: 
What is the use of SAVEPOINT in MySQL?

Answer
Unlock FullStack.Cafe to open all answers and get your next figure job offer!
Share this blog post to open Expert question!
🤖 Having Machine Learning & DS Interview? Check  MLStack.Cafe - 1704 Data Science & ML Interview Questions & Answers!Having ML & DS Interview? Check 🤖 MLStack.Cafe - 1704 ML & DS Interview Questions and Answers
 

Rust has been Stack Overflow’s most loved language for four years in a row and emerged as a compelling language choice for both backend and system developers, offering a unique combination of memory safety, performance, concurrency without Data races...

Clean Architecture provides a clear and modular structure for building software systems, separating business rules from implementation details. It promotes maintainability by allowing for easier updates and changes to specific components without affe...

Azure Service Bus is a crucial component for Azure cloud developers as it provides reliable and scalable messaging capabilities. It enables decoupled communication between different components of a distributed system, promoting flexibility and resili...

Cosmos DB has gained popularity among developers and organizations across various industries, including finance, e-commerce, gaming, IoT, and more. Follow along and learn the 24 most common and advanced Azure Cosmos DB interview questions and answers...
More than any other NoSQL database, and dramatically more than any relational database, MongoDB's document-oriented data model makes it exceptionally easy to add or change fields, among other things. It unlocks Iteration on the project. Iteration f...
Unit Tests and Test Driven Development (TDD) help you really understand the design of the code you are working on. Instead of writing code to do something, you are starting by outlining all the conditions you are subjecting the code to and what outpu...
Domain-Driven Design is nothing magical but it is crucial to understand the importance of Ubiquitous Language, Domain Modeling, Context Mapping, extracting the Bounded Contexts correctly, designing efficient Aggregates and etc. before your next DDD p...
At its core, Microsoft Azure is a public cloud computing platform - with solutions including Infrastructure as a Service (IaaS), Platform as a Service (PaaS), and Software as a Service (SaaS) that can be used for services such as analytics, virtual c...
As an asynchronous event-driven JavaScript runtime, Node.js is designed to build scalable network applications. Follow along to refresh your knowledge and explore the 52 most frequently asked and advanced Node JS Interview Questions and Answers every...
Dependency Injection is most useful when you're aiming for code reuse, versatility and robustness to changes in your problem domain. DI is also useful for decoupling your system. DI also allows easier unit testing without having to hit a database and...