MySQL basic interview questions-from a certain website

1. There is 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 18? 15?

(1) If the table type is MyISAM, then it is 18

Because the MyISAM table will record the maximum ID of the auto-incremented primary key into the data file, restart MySQL to determine the maximum ID of the auto-incremented primary key.

ID will not be lost

(2) If the table type is InnoDB, then it is 15

The InnoDB table only records the maximum ID of the auto-incremented primary key into memory, so restart the database or modify the table.

OPTIMIZE operation will cause the maximum ID to be lost

2. What are the technical characteristics of Mysql?

Mysql database software is a client or server system that includes: support for a variety of client programs and libraries

Threaded SQL server, different backends, extensive application programming interfaces and management tools.

3. What is the Heap table?

HEAP tables exist in memory and are used for temporary high-speed storage.

BLOB or TEXT fields are not allowed

Only the 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 for Mysql server is 3306.

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

Mysql is open source software, ready to use without any payment.

Mysql is a portable GUI with a command prompt.

Query browser support management using Mysql

6. How to distinguish between FLOAT and DOUBLE?

Here are the differences 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 18 bits of precision and eight bytes.

7. Distinguish between CHAR_LENGTH and LENGTH?

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

8. Please briefly describe the names of the four transaction isolation levels supported by InnoDB in Mysql, and the differences between levels? The four isolation levels defined by the SQL standard are:

read uncommited: read uncommitted data read committed: dirty read, non-repeatable read repeatable read: rereadable serializable: serial things

9. What is the usage of ENUM in Mysql?

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

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

10. How to define REGEXP?

REGEXP is a pattern match, where the pattern is matched anywhere in the search value.

11. What is the difference between CHAR and VARCHAR?

Here are the differences between CHAR and VARCHAR:

CHAR and VARCHAR types differ in storage and retrieval

The CHAR column length is fixed to the length declared when creating the table, 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 are removed when retrieving CHAR values.

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

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 Mysql version.

14. What storage engine is used in Mysql? Storage engines are called table types, and data is stored in files using various techniques.

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?

TIMESTAMP columns are updated with Zero when the table is created. The UPDATE CURRENT_TIMESTAMP modifier updates the timestamp field to the current time whenever other fields in the table change.

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

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

Primary keys are also candidate keys. By convention, candidate keys can be designated as primary keys and can be used for any foreign key references.

18. How to log in to Mysql using Unix shell?

We can log in with the following command:

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

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?

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

The size of the Heal table can be controlled through a 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 fixed width. Dynamic MyISAM tables will have fields like TEXT, BLOB, etc. to accommodate data types of different lengths. Click here for the most comprehensive summary of Alibaba interview questions.

MyISAM Static is easier to recover from in compromised situations.

23. What is a federated table?

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

24. What will happen if a table has a column defined as TIMESTAMP?

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

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

It will stop incrementing and any further insertions will generate an error because the key is already in use.

26. How can I find out which auto-increment was assigned during the last insert?

LAST_INSERT_ID will return the last value assigned by Auto_increment and does not require specifying a table name.

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

Indexes are defined for tables in the following ways:

SHOW INDEX FROM

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

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

29. How to convert between Unix and Mysql timestamps?

UNIX_TIMESTAMP is the 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 in column comparisons in a SELECT statement operator.

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

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

SELECT COUNT(user_id)FROM users;

32. Are Mysql queries 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 %.

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?

A 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 differ only in the maximum length they can hold a value.

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 the BLOB and TEXT types is that BLOB values ​​are sorted and compared case-sensitively, while TEXT values ​​are case-insensitive.

35. What is the difference between mysql_fetch_array and mysql_fetch_object?

The following are the differences between mysql_fetch_array and mysql_fetch_object:

mysql_fetch_array() - Returns the result rows 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 table be stored and its storage format also provided?

Each MyISAM table is stored on disk in three formats:

·".frm" file storage table definition

·Data files have the “.MYD” (MYData) extension

Index files have a ".MYI" (MYIndex) extension

38. What are the different tables in Mysql?

There are 5 types of tables:

MyISAM

Heap

Merge

INNODB

ISAM

MyISAM is the default storage engine for Mysql.

39. What is ISAM?

ISAM stands for Indexed Sequential Access Method. It was developed by IBM for storing and retrieving data on secondary storage systems such as tapes.

40. What is InnoDB?

lnnoDB is an Innobase Oy transaction-safe storage engine developed by Oracle Corporation.

41. How to optimize DISTINCT in Mysql?

DISTINCT is converted to GROUP BY on all columns and used with an 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 enter a character as a hexadecimal number, you can enter the hexadecimal number with single quotes and the prefix (X), or just enter the hexadecimal number with the (Ox) prefix.

If the expression context is a string, the string of hexadecimal digits is 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?

You can create up to 16 index columns on any standard table.

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

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

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

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 the Mysql table?

There are six triggers allowed in the 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 are general SQL functions?

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

FORMAT(X, D) - Format the number X to D significant digits.

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

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

MONTH(), DAY(), YEAR(), WEEK(), WEEKDAY() - Extracts the given data from a date value. HOUR(), MINUTE(), SECOND() - Extract the given data from the time value. DATEDIFF(A,B) - Determines the difference between two dates, often used for calculating age SUBTIMES(A,B) - Determines the difference between two dates.

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

50. Explain access control lists

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 helps troubleshoot problems where users cannot connect.

Mysql caches ACLs (also called authorization tables) in memory. When a user attempts to authenticate or run a command, MySQL checks the ACL for authentication information and permissions in a predetermined order.

51. Does MYSQL support transactions?

In the default mode, MYSQL is in autocommit mode, and all database update operations will be submitted immediately, so by default, mysql does not support transactions.

But if your MYSQL table type uses InnoDB Tables or BDB tables, your MYSQL can use transaction processing. Use SET AUTOCOMMIT=0 to enable MYSQL to allow non-autocommit mode. In non-autocommit mode, you must use COMMIT to commit your changes, or use ROLLBACK to roll back your changes.

Examples are as follows:

one

START TRANSACTION;

SELECT @A:=SUM(salary) FROM table1 WHERE type=1;

UPDATE table2 SET summmary=@A WHERE type=1;

COMMIT;

52. What field type is best for recording currency in mysql?

The NUMERIC and DECIMAL types are implemented by Mysql as the same type, which is allowed by the SQL92 standard. They are used to store values ​​whose exact accuracy is extremely important, such as money-related data. When declaring a class to be one of these types, precision and scale can (and usually are) specified; click here for a comprehensive summary of Alibaba interview questions.

For example:

salary DECIMAL(9,2)

In this example, 9 (precision) represents the total number of decimal places that will be used to store the value, while 2 (scale) represents the number of digits after the decimal point that will be used to store the value.

Therefore, in this case, the range of values ​​that can be stored in the salary column is from -9999999.99 to 9999999.99. In ANSI/ISO SQL92, the syntax DECIMAL§ is equivalent to DECIMAL(p,0).

Likewise, the syntax DECIMAL is equivalent to DECIMAL(p,0), where the implementation is allowed to determine the value p. Mysql does not currently support any of these variants of the DECIMAL/NUMERIC data type.

This is generally not a serious problem, as the main benefit of these types comes from the ability to clearly control precision and scale.

DECIMAL and NUMERIC values ​​are stored as strings rather than as binary floating point numbers in order to preserve the decimal precision of those values.

One character for each digit of the value, decimal point (if scale>0), and "-" sign (for negative values). If scale is 0,

DECIMAL and NUMERIC values ​​do not contain a decimal point or fractional part.

DECIMAL and NUMERIC are worth the same maximum range as DOUBLE, but for a given DECIMAL or

For NUMERIC columns, the actual range may be limited by the precision or scale of the given column.

When such a column is assigned a value with more digits after the decimal point than allowed by the specified scale, the value is rounded according to scale.

When a DECIMAL or NUMERIC column is assigned a value whose size exceeds the range implied by the specified (or default) precision and scale, MySQL stores the corresponding endpoint value representing that range.

I hope this article helps you improve your skills. Those of you who feel that learning is difficult and even frustrating, don’t worry, I think if you are willing to try some of the points introduced in this article, you will move forward and overcome this feeling. These points may not apply to you, but you will understand an important lesson: Accepting that you feel stuck is the first step to getting out of it.

53. Under what circumstances are MYSQL data tables easily damaged?

A sudden power outage on the server resulted in data file corruption.

Force shutdown without first shutting down the mysql service, etc.

54. What are the tables related to permissions in MySQL?

The Mysql server controls user access to the database through the permission table. The permission table is stored in the mysql database and initialized by the mysql_install_db script. These permission tables are user, db, table_priv, columns_priv and host.

55. What kinds of locks are there in Mysql?

MyISAM supports table locks, InnoDB supports table locks and row locks, and the default is row locks.

Table-level lock: low overhead, fast locking, and no deadlock. The locking granularity is large, the probability of lock conflict is the highest, and the amount of concurrency is the lowest.

Row-level locking: high overhead, slow locking, and deadlock may occur. The lock strength is small, the probability of lock conflict is small, and the concurrency is the highest.

Guess you like

Origin blog.csdn.net/qq_31536117/article/details/135029654