MySQL Interview

1. What is MySQL?
MySQL is an open source DBMS which is built, supported and distributed by MySQL AB (now acquired by Oracle)
2. What are the technical features of MySQL?
MySQL database software is a client or server system which includes
  • Multithreaded SQL server supporting various client programs and libraries
  • Different backend
  • Wide range of application programming interfaces and
  • Administrative tools.
3. Compare MySQL Vs. SQL Server
Criteria MySQL SQL Server
Targeted towards Internet servers & Open Source software Corporate & Enterprise market
Functionality Speed Administration, Graphical data modelling
Works with Assumes internet access Administration, Graphical data modelling
4. Why MySQL is used?
MySQL database server is reliable, fast and very easy to use. This software can be downloaded as freeware and can be downloaded from the internet.
5. What are Heap tables?
HEAP tables are present in memory and they are used for high speed storage on temporary basis.
  • BLOB or TEXT fields are not allowed
  • Only comparison operators can be used =, <,>, = >,=<
  • AUTO_INCREMENT is not supported by HEAP tables
  • Indexes should be NOT NULL
6. What do DDL, DML, and DCL stand for?
DDL is the abbreviation for Data Definition Language dealing with database schemas as well as the description of how data resides in the database. An example is CREATE TABLE command. DML denotes Data Manipulation Language such as SELECT, INSERT etc. DCL stands for Data Control Language and includes commands like GRANT, REVOKE etc.
7. What is the default port for MySQL Server?
The default port for MySQL server is 3306.
8. What are the common MySQL functions?
Common MySQL functions are as follows: • NOWO – function for returning current date and time as single value. • CURRDATEO – function for returning the current date or time. • CONCAT (X, Y) – function to concatenates two string values creating single string output. • DATEDIFF (X, Y) – function to determine difference two dates.
9. What is the difference between CHAR and VARCHAR?
When the table is created, CHAR is used to define the fixed length of the table and columns. The length value could be in the range of 1-255. VARCHAR command is given to adjust the column and table length as required.
10. What are HEAP Tables?
Basically HEAP tables are in-memory and used for high speed temporary storages. But TEXT or BLOB fields are not allowed within them. They also do not support AUTO INCREMENT.
11. What is the syntax for concatenating tables in MySQL?
The syntax for concatenating tables is MySQL is CONCAT (string 1, string 2, string 3)
12. What are the limits for using columns to create the Index?
The maximum limits of indexed columns that could be created for any table is 16.
13. What are the different types of strings in Database columns in MySQL?
Different types of strings that can be used for database columns are SET, BLOB, VARCHAR, TEX, ENUM, and CHAR.
14. Is there an object oriented version of MySQL library functions?
MySQLi is the object oriented version of MySQL and it interfaces in PHP.
15. What is the storage engine for MySQL?
Storage tables are named as table types. The data is stored in the files using multiple techniques such as indexing, locking levels, capabilities and functions.
16. What are the advantages of MySQL when compared with Oracle?
  • MySQL is open source software which is available at any time and has no cost involved.
  • MySQL is portable
  • GUI with command prompt.
  • Administration is supported using MySQL Query Browser
17. Define REGEXP?
REGEXP is a pattern match in which matches pattern anywhere in the search value.
18. Give string types available for column?
The string types are:
  • SET
  • BLOB
  • ENUM
  • CHAR
  • TEXT
19. What are the drivers in MySQL?
Following are the drivers available in MySQL:
  • PHP Driver
  • JDBC Driver
  • ODBC Driver
  • PYTHON Driver
  • PERL Driver
  • RUBY Driver
  • CAP11PHP Driver
  • Ado.net5.mxj
20. What does a TIMESTAMP do on UPDATE CURRENT_TIMESTAMP data type?
TIMESTAMP column is updated with Zero when the table is created. UPDATE CURRENT_TIMESTAMP modifier updates the timestamp field to current time whenever there is a change in other fields of the table.
21. How do you control the max size of a HEAP table?
Maximum size of Heal table can be controlled by MySQL config variable called max_heap_table_size.
22. What, if a table has one column defined as TIMESTAMP?
Timestamp field gets the current timestamp whenever the row gets altered.
23. What happens when the column is set to AUTO INCREMENT and if you reach maximum value in the table?
It stops incrementing. Any further inserts are going to produce an error, since the key has been used already.
24. Explain Access Control Lists.
An ACL (Access Control List) is a list of permissions that is associated with an object. This list is the basis for MySQL server’s security model and it helps in troubleshooting problems like users not being able to connect.
MySQL keeps the ACLs (also called grant tables) cached in memory. When a user tries to authenticate or run a command, MySQL checks the authentication information and permissions against the ACLs, in a predetermined order.
25. What are all the Common SQL Function?
  • CONCAT(A, B) – Concatenates two string values to create a single string output. Often used to combine two or more fields into one single field.
  • FORMAT(X, D) – Formats the number X to D significant digits.
  • CURRDATE(), CURRTIME() – Returns the current date or time.
  • NOW() – Returns the current date and time as one value.
  • MONTH(), DAY(), YEAR(), WEEK(), WEEKDAY() – Extracts the given data from a date value.
  • HOUR(), MINUTE(), SECOND() – Extracts the given data from a time value.
  • DATEDIFF(A, B) – Determines the difference between two dates and it is commonly used to calculate age
  • SUBTIMES(A, B) – Determines the difference between two times.
  • FROMDAYS(INT) – Converts an integer number of days into a date value.
26. What are the nonstandard string types?
Following are Non-Standard string types:
  • TEXT
27. How many TRIGGERS are allowed in MySql table?
SIX triggers are allowed in MySql table. They are as follows:
28. What are the objects can be created using CREATE statement?
Following objects are created using CREATE statement:
  • USER
  • VIEW
29. What is the different between NOW() and CURRENT_DATE()?
NOW () command is used to show current year,month,date with hours,minutes and seconds.
CURRENT_DATE() shows current year,month and date only.
30. How many columns can be used for creating Index?
Maximum of 16 indexed columns can be created for any standard table.
31. How to display top 40 rows?
SELECT * FROM Employee LIMIT 0,40;
32. How to enter Characters as HEX Numbers?
If you want to enter characters as HEX numbers, you can enter HEX numbers with single quotes and a prefix of (X), or just prefix HEX numbers with (Ox). A HEX number string will be automatically converted into a character string, if the expression context is a string.
33. How MySQL Optimizes DISTINCT?
DISTINCT is converted to a GROUP BY on all columns and it will be combined with ORDER BY clause.
SELECT DISTINCT t1.a FROM t1,t2 where t1.a=t2.a;
34. What are the column comparisons operators?
The = , <>, <=, <,>=, >,<<,>>, <=>, AND, OR, or LIKE operators are used in column comparisons in SELECT statements.
35. How can we get the number of rows affected by query?
SELECT COUNT (emp_id) FROM Employee;
36. Is Mysql query is case sensitive?
For example-
SeLect version(), current_date;
seleCt vErSiOn(), current_DATE;
All these examples are same. It is not case sensitive.
37. What is the difference between the LIKE and REGEXP operators?
LIKE and REGEXP operators are used to express with ^ and %.
SELECT * FROM employee WHERE emp_name REGEXP "^b";
SELECT * FROM employee WHERE emp_name LIKE "%b";
38. What is the difference between BLOB AND TEXT?
A BLOB is a binary large object that can hold a variable amount of data. There are four types of BLOB –
  • BLOB

They all differ only in the maximum length of the values they can hold.
A TEXT is a case-insensitive BLOB. The four TEXT types
  • TEXT