Top 40 Mysql Dba Interview Questions You Must Prepare 19.Mar.2024

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, 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.

REGEXP is a pattern match using regular expression. Regular expression is a powerful way of specifying a pattern for a complex search.

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.

Mysql_close() cannot be used to close the persistent connection. Though it can be used to close connection opened by mysql_connect().

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.

Mysql_connect:

  • It opens a new connection to the database.
  • Every time you need to open and close database connection, depending on the request.
  • Opens page every time when it loaded.

Mysql_pconnect:

  • In Mysql_pconnect, "p" stands for persistent connection so it opens the persistent connection.
  • the database connection can not be closed.
  • 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.

MyISAM table is stored on disk in three formats.

  • '.frm' file : storing the table definition
  • '.MYD' (MYData): data file
  • '.MYI' (MYIndex): index file

The SELECT command is used to view the content of the table in MySQL.

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

The default location of MySQL data directory in windows is C:mysqldata or C:Program FilesMySQLMySQL Server 5.0 data.

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_object field can be accessed as $result->name.
Using mysql_fetch_array field can be accessed as $result->[name].
Using mysql_fetch_row($result) where $result is the result resource returned from a successful query executed using the mysql_query() function.
Example:
1.$result = mysql_query("SELECT * from students");  
2.while($row = mysql_fetch_row($result))  
3.{  
4.Some statement;  
5.}  

SQL is known as 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.

Heap tables:

  • Heap tables are found in memory. They are used for high speed storage on temporary basis. They do not allow BLOB or TEXT fields.
  • Heap tables do not support AUTO_INCREMENT.
  • Indexes should be NOT NULL.

Temporary tables:

  • The temporary tables are used to keep the temporary data. Sometimes it is very useful in cases to keep temporary data. Temporary table is deleted after 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).

MySQL has the following technical specifications -

  • Flexible structure
  • High performance
  • Manageable and easy to use
  • Replication and high availability
  • Security and storage management

Let us take a table named employee.

To find Nth highest salary is:
@select distinct(salary) from employee order by salary desc limit n-1,1  

if you want to find 3rd largest salary:
@select distinct(salary) from employee order by salary desc limit 2,1 

A list of differences between CHAR and VARCHAR:

  • CHAR and VARCHAR types are different in storage and retrieval.
  • CHAR column length is fixed to the length that is declared while creating table. The length value ranges from 1 and 25@
  • When CHAR values are stored then they are right padded using spaces to specific length. Trailing spaces are removed when CHAR values are retrieved.

To get current date, use the following syntax:
SELECT CURRENT_DATE();  

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.

BLOB is an acronym stands for binary large object. It is used to hold a variable amount of data.

There are four types of BLOB.

  1. TINYBLOB
  2. BLOB
  3. MEDIUMBLOB
  4. LONGBLOB

The differences among all these are the maximum length of values they can hold. TEXT is 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.

There are four types of TEXT.

  1. TINYTEXT
  2. TEXT
  3. MEDIUMTEXT
  4. LONGTEXT

MySQL is written in C and C++ and its SQL parser is written in yacc.

  • Install antivirus and configure the operating system's firewall.
  • Never use the MySQL Server as the UNIX root user.
  • Change root username and password
  • Restrict or disable remote access.

  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.

MySQL is a multithreaded, multi-user SQL database management system which has more than 11 million installations. This is the world's second most popular and widely used open source database.

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.

You can create maximum of 16 indexed columns for a standard table.

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').

There are only six Triggers allowed to use in MySQL database.

  1. Before Insert
  2. After Insert
  3. Before Update
  4. After Update
  5. Before Delete
  6. After Delete

MySQL default port number is 3306.

It is easy to backing 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 backup. Then specify the option you want under export and save the output.

In MySQL, regular expressions are used in queries for searching a pattern in a string.

  • * Matches 0 more instances of the string preceding it.
  • + matches 1 more instances of the string preceding it.
  • ? Matches 0 or 1 instances of the string preceding it.
  • . Matches a single character.
  • [abc] matches a or b or z
  • | separates strings
  • ^ anchors the match from the start.
  • "." 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):

  1. Select employee_name  
  2. From employee  
  3. Where employee_name REGEXP '1000'  
  4. Order by employee_name  

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.

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.

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 temporary basis. They do not allow BLOB or TEXT fields.

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.

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.

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. MySQL is not so efficient for large scale databases.
  2. It does not support COMMIT and STORED PROCEDURES functions version less than 5.@
  3. Tractions are not handled very efficiently.

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.

Mysqladmin -u root -p password "newpassword".

A trigger is a set of codes that executes in response to some events.