MySQL > select * from user where MySQL > select * from user where MySQL >
- Table lock: low overhead, fast lock; No deadlocks occur; The lock granularity is large, and the probability of lock conflict is high and the concurrency is low.
- Row-level lock: expensive, slow lock; Deadlocks occur; The lock granularity is the lowest, the probability of lock conflict is the lowest, and the concurrency is the highest.
- Page lock: the overhead and lock time are between table lock and row lock. Deadlocks occur; The locking granularity is between table locks and row locks, and the concurrency is average.
2, What are the different tables in MySQL?
- MyISAM
- Heap
- Merge
- INNODB
- ISAM
3. Briefly describe the difference between MyISAM and InnoDB in MySQL database
- Transactions are not supported, but each query is atomic;
- Supports table-level locking, that is, each operation locks the entire table.
- The total number of rows stored in the table;
- A MYISAM table has three files: index file, table structure file, data file;
- The data domain of the index file stores Pointers to the data file. Secondary indexes are basically the same as primary indexes, but secondary indexes are not guaranteed to be unique.
- Acid-supported transactions, which support four isolation levels of transactions;
- Row-level locking and foreign key constraints are supported, so write concurrency is supported.
4, MySQL InnoDB supports four transaction isolation levels, and the difference between each level?
- Read uncommited: Uncommitted data is read
- Read COMMITTED: Indicates dirty reads and cannot be committed
- Repeatable read: repeatable
- Serializable: Serial things
5, What is the difference between CHAR and VARCHAR?
- The CHAR and VARCHAR types differ in storage and retrieval
- When CHAR values are stored, they are filled with Spaces to a specific length. Trailing Spaces are removed when retrieving CHAR values.
What is the difference between a primary key and a candidate key?
- Each row of a table is uniquely identified by a primary key, and a table has only one primary key.
- Primary keys are also candidates. By convention, candidate keys can be specified as primary keys and can be used for any foreign key reference.
7. What is Myisamchk used for?
It is used to compress MyISAM tables, which reduces disk or memory usage.
What is the difference between MyISAM Static and MyISAM Dynamic?
MyISAM Static is easier to recover from damage.
8. What happens if a table has a column defined as TIMESTAMP?
What happens if the maximum value in the table is reached when the column is set to AUTO INCREMENT?
How do I find out which automatic increment was allocated on the last insert?
9. How do you see all the indexes defined for the table?
SHOW INDEX FROM <tablename>;Copy the code
10, What do % and _ in LIKE declarations mean?
How to convert between Unix and MySQL timestamps?
- UNIX_TIMESTAMP is a command that converts MySQL timestamp to Unix timestamp
- FROM_UNIXTIME is the command to convert a Unix timestamp to a MySQL timestamp
What is the column comparison operator?
What’s the difference between a BLOB and a TEXT?
- A BLOB is a binary object that can hold a variable amount of data. TEXT is a case insensitive BLOB.
- The only difference between BLOB and TEXT types is that BLOB values are case-sensitive when sorting and comparing, while TEXT values are case-insensitive.
What is the difference between MySQL_fetch_array and MySQL_fetch_object
- MySQL_fetch_array () – Returns the result row as an associative array or as a regular array from the database.
- MySQL_fetch_object – Returns the result row as an object from the database.
14. Where will MyISAM tables be stored and their storage format provided?
- ·. FRM file storage table definition
- · Data files have the extension “.myd “(MYData)
- Index files have the.myi (MYIndex) extension
MySQL: How to optimize DISTINCT?
- DISTINCT is converted to GROUP BY on all columns and is used in combination with the ORDER BY clause.
- SELECT DISTINCT t1.a FROM t1,t2 where t1.a=t2.a;
16. How to display the first 50 lines?
- SELECT*FROM
- LIMIT 0, 50;
17, How many columns can be used to create an index?
- Up to 16 index columns can be created for any standard table.
What’s 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 () displays only the current year, month, and date.
What is a nonstandard string type?
- TINYTEXT
- TEXT
- MEDIUMTEXT
- LONGTEXT
What are generic SQL functions?
FROMDAYS (INT) – Converts integer days to date values.
Does MySQL support transactions?
22, what is the best field type to record currency in MySQL
Salary is a DECIMAL (9, 2)Copy the code
MySQL > select * from ‘MySQL’;
24. What can be the string type of a column?
- SET
- BLOB
- ENUM
- CHAR
- TEXT
MySQL database as the storage of the release system, more than 50,000 increments a day, is expected to operate and maintain for three years, how to optimize?
- Well-designed database structure allows partial data redundancy, avoids join query as far as possible, and improves efficiency.
- Select the appropriate table field data type and storage engine, and add indexes as appropriate.
- MySQL library master separated from read and write.
- Find regular table, reduce the amount of data in a single table to improve the query speed.
- Add caching mechanisms such as memcached, APC, etc.
- Pages that do not change often, generate static pages.
- Write efficient SQL. SELECT field_1,field_2, fieldd_3 FROM TABLE
Lock optimization strategy
- Reading and writing separation
- Subsection locking
- Reduces the duration of lock holding
- Multiple threads try to fetch resources in the same order
The underlying implementation principle and optimization of index
When an index is set but cannot be used
- LIKE statements beginning with “%”, fuzzy match
- The index is not used before OR after the OR statement
- Implicit conversion of data type (vARCHar may be automatically converted to int if not quoted)
29, How to optimize MySQL in practice
- SQL statement and index optimization
- Optimization of database table structure
- Optimization of system configuration
- Hardware optimization
30. Methods to optimize the database
- Use joins instead
- Instead of manually created temporary tables, use unions
- Transaction processing
- Lock tables and optimize transaction processing
- Apply foreign key, optimize lock table
- indexing
- Optimized query statement
31, simple description in MySQL, index, primary key, unique index, joint index, the difference between what is the effect on the performance of the database (from two aspects of reading and writing)
What is a transaction in a database?
- Atomicity: Indivisibility, where all transactions are executed or none are executed.
- Consistency or seriability. The execution of the transaction causes the database to transition from one correct state to another
- Isolation. Any changes made to data by that transaction are not allowed to be made available to any other transaction until the transaction has committed correctly,
- Persistence. Once a transaction is committed correctly, its results are permanently stored in the database, even if other failures occur after the transaction is committed.
33, The cause of SQL injection vulnerability? How to prevent it?
Filter out some keywords in SQL statements: UPDATE, INSERT, delete, select, *.
34, Select the appropriate data type for the fields in the table
35. Storage period
Indexing is a very important concept for relational databases. Please answer some questions about indexing:
1. What is the purpose of an index?
2. What are the negative effects of indexes on database systems?
What are the principles for indexing a table?
4, under what circumstances should not build index?
Explain the difference between external join, internal join and self-join in MySQL
Overview of transaction rollback mechanism in Myql
What are the parts of SQL language? What are the operation keys for each section?
- Data definitions: Create Table,Alter Table,Drop Table, Craete/Drop Index, etc
- Data manipulation: Select, INSERT,update,delete,
- Data control: Grant, REVOKE
- Data query: select
What are integrity constraints?
Divided into the following four categories:
What is a lock?
Basic lock types: Locks include row-level locks and table-level locks
What is a view? What is a cursor?
What is a stored procedure? With what?
44. How to understand the three paradigms popularly?
- The first normal form: 1NF is the atomicity constraint on attributes, which requires attributes to have atomicity and cannot be decomposed again.
- Second normal form: 2NF is a constraint on the uniqueness of records, requiring records to have a unique identity, that is, the uniqueness of entities;
- Third normal form: 3NF is a constraint on field redundancy, that is, no field can be derived from another field, it requires that the field have no redundancy.
Multiple tables are required for query association, which reduces write efficiency and increases read efficiency and makes index optimization more difficult
What is a basic table? What is a view?
46. Describe the advantages of view?
- (1) View can simplify user operations
- (2) Views enable users to view the same data from multiple perspectives;
- (3) Views provide a degree of logical independence for the database;
- (4) View can provide security protection for confidential data.
47. What does NULL mean
What is the difference between a primary key, a foreign key, and an index?
- Definition: Primary key – Uniquely identifies a record, cannot be duplicated, and cannot be empty
- Foreign key – THE foreign key of a table is the primary key of another table. Foreign keys can have duplicate or null values
- Index – This field has no duplicate value, but can have a null value
- Primary key – used to ensure data integrity
- Foreign key – used to establish relationships with other tables
- Indexing – is to speed up query sorting
- Primary key – There can be only one primary key
- Foreign keys – A table can have more than one foreign key
- Indexes – A table can have multiple unique indexes
49. What can you use to ensure that fields in a table accept only values in a specified range?
What are the methods of SQL statement optimization? (Select a few)
- Joins between Where tables must precede other Where conditions, and conditions that filter out the maximum number of records must precede the end of the Where clause. HAVING finally.
- Replace IN with EXISTS and NOT EXISTS with NOT IN.
- Avoid calculations on indexed columns
- Avoid using IS NULL and IS NOT NULL on index columns
- Queries should be optimized to avoid full table scans, and indexes should be considered on where and order by columns first.
- Try to avoid null values for fields in the WHERE clause, as this will cause the engine to abandon the index for a full table scan
- Expression operations on fields in the WHERE clause should be avoided as much as possible, which can cause the engine to abandon indexes for a full table scan
Conclusion:
【 Spring Recruitment series 】springBoot soul 22 ask!
【 Prepare for spring recruitment series 】50 micro service interview questions in detail
【 Prepare for spring recruitment series 】27 MyBatis interview real questions detailed explanation
Q: How do you nail an interviewer
Spring recruitment is coming, sorted out some classic interview questions often tested by big factory, friends in need can pay attention to wechat public number: Java Programmers gathering place.