July 19, 2019

Srikaanth

Genpact MySQL Most Frequently Asked Interview Questions

What is the use of i-am-a-dummy flag in MySQL?

The flag i-am-a-dummy flag makes the MySQL engine to deny the UPDATE and DELETE commands unless the WHERE clause is present.

What are the differences between MySQL_fetch_array(), MySQL_fetch_object(), MySQL_fetch_row()?

The mysql_fetch_object() returns the result from the database as an object.
Ex: $result->name

The mysql_fetch_array() returns the result from the database as an associative array or numeric array or both by using mysql_NUM or mysql_ASSOC options.
EX: $result[0] ,$result['name']

The mysql_fetch_row() returns the result from the database as a numeric array.
Ex: $result[0]

What is difference between mysql_connect and mysql_pconnect?

Mysql_connect:

- Opens a new connection to the database.
- The database connection can be closed.
- Opens the page every time the page is loaded.

Mysql_pconnect:

- Opens a persistent connection to the database.
- The database connection can not be closed.
- The page need not be opened every time the page is loaded.
Genpact MySQL Most Frequently Asked Latest Interview Questions Answers
Genpact MySQL Most Frequently Asked Latest Interview Questions Answers

What is MySQL data directory? How to determine the location of the data directory?

MySQL data directory is most important location in which all MySQL databases are stored. The default data directory is located in the file mysql.

If the out of the space is the issue, then the directory need to be moved another location. Before moving, the database need to be closed. After moving the MySQL configuration file need to be edited. Look for the ‘datadir’ entry and change the path to the new directory.

What you can use Regular Expression for in MySQL? Support your answer with an example.

Regular expressions are a set of characters. Regular expressions are used for finding certain sequences in strings.

The following are the regular expression characters:

- * Represents matching characters that are 0 or more occurrences of the string that precedes it.
- + Represents matching characters that are 1 or more occurrences of the string that precedes it.
- ? Represents matching characters that are 0 or 1 occurrences of the string that precedes it.
- . Represents single character pattern matching.
- [abc] Represents matching characters that is either a or b or c.
- | Used for separation of strings.
- ^ Finds the matching pattern starting from the beginning.

To match the input characters with database tables, REGEXP is used. For example:
Select cityname
from territories
where cityname REGEXP ‘^(jo)*’;

The above query returns all city names that has the substring ‘jo’.

What are the steps required to view your MYSQL database?

There are certain steps that are required to before you can view MySQL database and they are as follows:

1. Login as database user

example:
[root@ tmp]# mysql -u mysqluser -p sales

2. List all your MySQL databases: use the show command to view the list of all available MySQL databases.

example
To view sales database use the command shown below:

mysql > show databases;
| Database |
| salesdata |

Write a command to view MySQL database table structure

To view the database table structure describe command is used that provides the list of all the data fields used in the database table.

Example

A table named sales will have the four fields like: name, description, num and date.

mysql > describe test;
| Field | Type | Null | Key | Default | Extra|
| num | int(11)| |PRI | NULL | auto_increment |
| date | date| | MUL | 0000-00-00 |
| name | varchar(50) | MUL |
| description | varchar(75) | YES | | NULL

Write a command to view the content of the table

To view all the data that is contained inside a table named sales use the select command. For example: to see the data of first row in a table using the command as:
mysql > select * from sales limit 1;

If the database is created recently then it will give a blank listing, but after the data is being entered it will show the full listing in a tabular form.

What is the procedure to configure the application of MYSQL?

The procedure to configure the application of MySQL is:

1. First create a database
2. Test the database by informing about the database name, IP address of database client server, username and password of application.
3. Edit the special application specific configuration file using a GUI or command line.
4. Configure the language with which MySQL will interact.

What are the applications required to support MYSQL?

The applications that are required to support MySQL are as follows:

1. php-mysql MySQL database is used specifically to support PHP
2. perl-DBI : provides generic Perl interface for interacting with relational databases
3. perl-DBD-MySQL database specific support for Perl
4. Web server is required to configure the database and its configuration
5. Programming language is required which supports MySQL.

Write a query to stop MYSQL in unix

The query to stop MySQL is quite useful when an error is occurred or when data has to be saved from any mishap. It is also used for retrieving the root password because it is either easily forgotten or misplaced. To stop the service the following command is required:
Stop MySQL
[root@ tmp]# service mysqld stop
Stopping MySQL: [ OK ]
[root@ tmp]#

Write a query to MYSQL in safe mode and to change the root password

To start MySQL in safe mode, mysqld_safe command is used which allow it to run in the safe mode and it also doesn’t allow the reading of tables with the database passwords:
[root@ ]# mysqld_safe --skip-grant-tables --skip-networking &[1] 13007
[root@ ]# Starting mysqld daemon with databases from /var/lib/mysql
[root@ ]#

After running the MySQL in safe mode the password protection gets removed and to use the password protection mechanism a command is used as follows:
mysql -u root command
[root@bigboy tmp]# mysql -u root

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.16
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> [ a message is being shown which allow user to take the control of the root]

How to take MYSQL database backup?

To take the database backup use the following syntax:
mysqldump --add-drop-table -u [username] -p[password] [database] > [backup_file]

This command will take the database backup by knowing the username and password for the database connection and dropping any table which is being deleted or not in use. It is always a good practice to take the backup of mysql as it contains all the database information that a user can access. While using the command keep a note that there should not be any space between –p switch and password, if there is then you will get a syntax error.

Write a command with which MySQL table can be repaired

The command syntax with which mysql table can be repaired is as follows:
REPAIR TABLE tablename;
REPAIR TABLE tablename QUICK;
REPAIR TABLE tablename EXTENDED;

The command will just do as it says repair a specified table, but if QUICK or EXTENDED is used then the meaning of it changes. In case of QUICK it will repair only the index tree, whereas in case of EXTENDED it will create index row by row and repair it.

What are the different tables present 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:

1. MyISAM
2. Heap
3. Merge
4. INNO DB
5. ISAM

What does the file with the extension: frm, myd, and myi contain?

MySQL default table type is MyISAM, where there are three kind of files that are stored inside MyISAM. The file names begin with the table name and have the extensions such as frm, myd and myi. The explanation of each file is given below:

.frm file consists of the table definition that are stored in the database
.myd is an extension that is used by a data file.
.myi is an extension that is used by index file.

What is the difference between MYSQL and SQL?

- SQL is known as standard query language, as the name implies it is the language which is used to interact with the database like MySQL.

- MySQL is a database that store various types of data and keep it safe. A PHP script is required to store and retrieve the values inside the database.

How database are managed?

Database is a collection of data and it is managed by a database server, which is a special program that is also known as MySQL database server. Application that you create usually communicates with the database server in the language which it can understand; mostly SQL language is used for communication. Database server in return interacts with the web server on same server or computer. Database server and web server result in the data which is being shown on the web.

Subscribe to get more Posts :