ThoughtWorks MySQL Interview Questions Answers

What is difference between mysql_connect and mysql_pconnect?

Mysql_connect() opens a new connection to the database while mysql_pconnect() opens a persistent connection to the database. This means that each time the page is loaded mysql_pconnect() does not open the database. Mysql_close() cannot be used to close the persistent connection. Though it can be used to close mysql_connect().

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

MySQL stores its data on the disk on the data dictionary. Each subdirectory under this data dictionary represents a MySQL database, inside those directories. By default the information managed my MySQL = server mysqld is stored in data directory.A default location of data directory in windows is C:\mysql\data or C:\Program Files\MySQL\MySQL Server 5.0 \data..
ThoughtWorks Most Frequently Asked Latest MySQL Interview Questions Answers
ThoughtWorks Most Frequently Asked Latest MySQL Interview Questions Answers

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

Regular expressions in MySql are used in queries for searching a pattern in a string.

1. * Matches 0 more instances of the string preceding it.
2. + matches 1 more instances of the string preceding it.
3. ? Matches 0 or 1instances of the string preceding it.
4. . Matches a single character.
5. [abc] matches a or b or z
6. | separates strings
7. ^ anchors the match from the start.

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

“.” Can be used to match any single character. “|” can be used to match either of the two strings

How will you export tables as an XML file in MySQL?

From the command prompt type the following statement:
mysql -u test --xml -e 'SELECT * FROM t1' > t1.xml

where ‘–u test‘ is the user name, --xml indicates the type of the file is xml, -e for export

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.

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

Post a Comment

Previous Post Next Post