In 2020, I summarized these 50 high-frequency MySQL interview questions!

1. A table with an ID auto-incrementing primary key. After inserting 17 records, delete the 15th, 16th, and 17th records, restart Mysql, and insert another record. Is the ID of this record 18 or 15?

image.png

2. What are the technical characteristics of Mysql?

Mysql database software is a client or server system, which includes: a multi-threaded SQL server supporting various client programs and libraries, different back ends, a wide range of application programming interfaces and management tools.

3. What is Heap table?

The HEAP table exists in memory and is used for temporary high-speed storage.

  • BLOB or TEXT fields are not allowed

  • Only comparison operators =, <, >, =>, = <

  • HEAP table does not support AUTO_INCREMENT

  • Index cannot be NULL

4. What is the default port of Mysql server?

The default port of Mysql server is 3306.

5. Compared with Oracle, what are the advantages of Mysql?

  • Mysql is open source software and is available at any time without payment.

  • Mysql is portable

  • GUI with command prompt.

  • Use Mysql query browser support management

6. How to distinguish FLOAT and DOUBLE?

The following is the difference between FLOAT and DOUBLE:

  • Floating point numbers are stored in FLOAT with 8-bit precision and have four bytes.

  • Floating point numbers are stored in DOUBLE, with a precision of 18 bits and eight bytes.

7. What is the difference between CHAR_LENGTH and LENGTH?

CHAR_LENGTH is the number of characters, and LENGTH is the number of bytes. These two data for Latin characters are the same, but for Unicode and other encodings, they are different.

8. Please briefly describe the names of the four transaction isolation levels supported by InnoDB in Mysql and the differences between each level?

The four isolation levels defined by the SQL standard are:

  • read uncommited: read uncommitted data

  • read committed: dirty read, non-repeatable read

  • repeatable read: repeatable read

  • serializable: serial things

image.png

image.png

9. What is the usage of ENUM in Mysql?

ENUM is a string object used to specify a set of predefined values ​​and can be used when creating a table.

Create table size(name ENUM('Smail,'Medium','Large');

10. How to define REGEXP?

REGEXP is pattern matching, where the matching pattern is anywhere in the search value.

11. What is the difference between CHAR and VARCHAR?

The following is the difference between CHAR and VARCHAR:

  • CHAR and VARCHAR types are different in storage and retrieval

  • The length of the CHAR column is fixed to the length declared when the table is created, and the length value range is 1 to 255

When CHAR values ​​are stored, they are padded with spaces to a specific length, and trailing spaces need to be deleted when retrieving CHAR values.

12. What can be the string type of the column?

The string types are:

  • SET

  • BLOB

  • ENUM

  • CHAR

  • TEXT

  • VARCHAR

13. How to get the current Mysql version?

SELECT VERSION(); Used to get the current version of Mysql.

14. What storage engine is used in Mysql?

The storage engine is called a table type, and data is stored in files using various technologies.

Technology involves:

  • Storage mechanism

  • Locking levels

  • Indexing

  • Capabilities and functions.

15. What is the Mysql driver?

The following are the drivers available in Mysql :

  • PHP driver

  • JDBC driver

  • ODBC driver

  • CWRAPPER

  • PYTHON driver

  • PERL driver

  • RUBY driver

  • CAP11PHP driver

  • Ado.net5.mxj

16. What does TIMESTAMP do on the UPDATE CURRENT_TIMESTAMP data type?

The TIMESTAMP column is updated with Zero when the table is created. As long as other fields in the table change, the UPDATE CURRENT_TIMESTAMP modifier updates the timestamp field to the current time.

17. What is the difference between primary key and candidate key?

Each row of the table is uniquely identified by the primary key, and a table has only one primary key.

The primary key is also a candidate key. By convention, candidate keys can be designated as primary keys and can be used for any foreign key references.

18. How to log in Mysql using Unix shell?

We can log in with the following command:

[mysql dir]/bin/mysql -h hostname -u -p

19. What is myisamchk used for?

It is used to compress MyISAM tables, which reduces disk or memory usage.

20. What are the method commands for MYSQL database server performance analysis?

image.png

21. How to control the maximum size of HEAP table?

The size of the Heal table can be controlled by the Mysql configuration variable called max_heap_table_size.

22. What is the difference between MyISAM Static and MyISAM Dynamic?

All fields on MyISAM Static have a fixed width. The dynamic MyISAM table will have fields like TEXT, BLOB, etc. to accommodate data types of different lengths. Click here for a summary of the most comprehensive set of Ali interview questions.

MyISAM Static is easier to recover in case of damage.

23. What is a federated table?

Federated tables allow access to tables located on other server databases.

24. If a table has a column defined as TIMESTAMP, what will happen?

Whenever the row is changed, the timestamp field will get the current timestamp.

25. When the column is set to AUTO INCREMENT, what happens if it reaches the maximum value in the table?

It will stop incrementing, and any further insertion will generate an error because the key has already been used.

26. How can I find out which auto increment was allocated during the last insertion?

LAST_INSERT_ID will return the last value assigned by Auto_increment, and there is no need to specify the table name.

27. How do you see all the indexes defined for the table?

The index is defined for the table in the following way:

SHOW INDEX FROM ;

28. What do% and _ in the LIKE statement mean?

% Corresponds to 0 or more characters, and _ is just one character in the LIKE statement.

29. How to convert between Unix and Mysql timestamps?

  • UNIX_TIMESTAMP is a command to convert from Mysql timestamp to Unix timestamp

  • FROM_UNIXTIME is the command to convert from Unix timestamp to Mysql timestamp

30. What is the column comparison operator?

Use =, <>, <=, <,> =, >, <<, >>, <=>, AND, OR or LIKE operators in the column comparison of the SELECT statement.

31. How do we get the number of rows affected by the query?

The number of rows can be obtained by the following code:

SELECT COUNT(user_id)FROM users;

32. Is Mysql query case sensitive?

Does not distinguish between

SELECT VERSION(), CURRENT_DATE;

SeLect version(), current_date;

seleCt vErSiOn(), current_DATE;

All these examples are the same, Mysql is not case sensitive.

33. What is the difference between LIKE and REGEXP operations?

The LIKE and REGEXP operators are used to represent ^ and %.

12

SELECT FROM employee WHERE emp_name REGEXP "^b";SELECT FROM employee WHERE emp_name LIKE "%b";

34. What is the difference between BLOB and TEXT?

BLOB is a binary object that can hold a variable amount of data. There are four types of BLOB −

  • TINYBLOB

  • BLOB

  • MEDIUMBLOB and

  • LONGBLOB

They can only differ in the maximum length of value they can hold.

TEXT is a case-insensitive BLOB. Four TEXT types

  • TINYTEXT

  • TEXT

  • MEDIUMTEXT and

  • LONGTEXT

They correspond to the four BLOB types and have the same maximum length and storage requirements.

The only difference between BLOB and TEXT types is that BLOB values ​​are case-sensitive when sorting and comparing, and TEXT values ​​are not case-sensitive.

35. What is the difference between mysql_fetch_array and mysql_fetch_object?

The following is the difference between mysql_fetch_array and mysql_fetch_object:

mysql_fetch_array()-returns the result row as an associative array or a regular array from the database.

mysql_fetch_object-returns result rows from the database as objects.

36. How do we run batch mode in mysql?

The following commands are used to run in batch mode:

mysql;

mysql mysql.out

37. Where will the MyISAM form be stored and also provide its storage format?

Each MyISAM table is stored on disk in three formats:

·".Frm" file storage table definition

·Data files have ".MYD" (MYData) extension

Index file has ".MYI" (MYIndex) extension

38. What are the different tables in Mysql?

There are 5 types of forms:

  • MyISAM

  • Heap

  • Merge

  • INNODB

  • ISAM

MyISAM is the default storage engine of Mysql.

39. What is ISAM?

ISAM is abbreviated as index sequential access method. It was developed by IBM to store and retrieve data on secondary storage systems such as magnetic tape.

40. What is InnoDB?

lnnoDB is an Innobase Oy transaction security storage engine developed by Oracle.

41. How does Mysql optimize DISTINCT?

DISTINCT is converted to GROUP BY on all columns and used in conjunction with the ORDER BY clause.

1

SELECT DISTINCT t1.a FROM t1,t2 where t1.a=t2.a;

42. How to input characters as hexadecimal numbers?

If you want to input characters as hexadecimal numbers, you can enter the hexadecimal numbers with single quotes and the prefix (X), or just use the (Ox) prefix to enter the hexadecimal numbers.

If the expression context is a string, the hexadecimal number string will be automatically converted to a string.

43. How to display the first 50 lines?

In Mysql, use the following code query to display the first 50 rows:

SELECT*FROM

LIMIT 0,50;

44. How many columns can be used to create an index?

Any standard table can create up to 16 index columns.

45. What is the difference between NOW() and CURRENT_DATE()?

The NOW() command is used to display the current year, month, date, hour, minute, and second.

CURRENT_DATE() only displays the current year, month and date.

46. ​​What kind of objects can be created using the CREATE statement?

The following objects are created using the CREATE statement:

  • DATABASE

  • EVENT

  • FUNCTION

  • INDEX

  • PROCEDURE

  • TABLE

  • TRIGGER

  • USER

  • VIEW

47. How many TRIGGERS are allowed in Mysql table?

Six triggers are allowed in Mysql table, as follows:

  • BEFORE INSERT

  • AFTER INSERT

  • BEFORE UPDATE

  • AFTER UPDATE

  • BEFORE DELETE

  • AFTER DELETE

48. What is a non-standard string type?

The following are non-standard string types:

  • TINYTEXT

  • TEXT

  • MEDIUMTEXT

  • LONGTEXT

49. What is a general SQL function?

  • CONCAT(A, B)-Concatenate two string values ​​to create a single string output. Usually used to combine two or more fields into one field.

  • FORMAT(X, D)- format the number X to D effective digits.

  • CURRDATE(), CURRTIME()-returns the current date or time.

  • NOW()-returns the current date and time as a value.

  • MONTH(), DAY(), YEAR(), WEEK(), WEEKDAY()-extract the given data from the date value.

  • HOUR(), MINUTE(), SECOND()-extract the given data from the time value.

  • DATEDIFF (A, B)-Determine the difference between two dates, usually used to calculate age

  • SUBTIMES (A, B)-Determine the difference between two times.

  • FROMDAYS (INT)-Convert integer days to date values.

50, explain the access control list

ACL (Access Control List) is a list of permissions associated with an object. This list is the basis of the Mysql server security model, and it helps to eliminate the problem that users cannot connect.

Mysql caches ACLs (also called authorization tables) in memory. When users try to authenticate or run commands, Mysql will check ACL authentication information and permissions in a predetermined order.

Guess you like

Origin blog.51cto.com/14975073/2577046