A. 初心者レベルの MySQL の質(zhì)問(wèn):
-
MySQL とは何ですか?
- MySQL は、データベースに格納されているデータへのアクセス、管理、操作に構(gòu)造化照會(huì)言語(yǔ) (SQL) を使用するオープンソースのリレーショナル データベース管理システム (RDBMS) です。
-
MySQL の主な機(jī)能は何ですか?
- オープンソース、クロスプラットフォームのサポート、高性能、複雑なクエリのサポート、セキュリティ機(jī)能、ACID 準(zhǔn)拠、スケーラビリティ、レプリケーション、クラスタリング。
-
リレーショナル データベースとは何ですか?
- リレーショナル データベースは、行と列で構(gòu)成されるテーブルにデータを格納するデータベースの一種です。各テーブルには一意のキーがあり、テーブル間の関係は外部キーを使用して確立されます。
-
SQL とは何ですか?
- SQL (Structured Query Language) は、データのクエリ、挿入、更新、削除などのタスクを含む、リレーショナル データベースの管理と操作に使用される標(biāo)準(zhǔn)プログラミング言語(yǔ)です。
-
MySQL のさまざまなデータ型とは何ですか?
- MySQL は次のようなさまざまなデータ型をサポートしています。
- 數(shù)値: INT、FLOAT、DOUBLE、DECIMAL
- 文字列: VARCHAR、TEXT、CHAR
- 日付と時(shí)刻: 日付、日時(shí)、タイムスタンプ、時(shí)刻
- バイナリ: BLOB、BINARY
- MySQL は次のようなさまざまなデータ型をサポートしています。
-
主キーとは何ですか?
- 主キーは、テーブル レコードの一意の識(shí)別子です。これにより、主キー列に重複した値が格納されなくなり、各テーブルに主キーを 1 つだけ持つことができます。
-
外部キーとは何ですか?
- 外部キーは、別のテーブルの行を一意に識(shí)別するテーブル內(nèi)のフィールド (またはフィールドのコレクション) で、2 つのテーブル間のリンクを確立し、參照整合性を強(qiáng)制します。
-
CHAR と VARCHAR の違いは何ですか?
- CHAR は固定長(zhǎng)文字列ですが、VARCHAR は可変長(zhǎng)文字列です。 CHAR は文字列の長(zhǎng)さが予測(cè)可能な場(chǎng)合に使用されますが、VARCHAR はさまざまな長(zhǎng)さに対してスペース効率が高くなります。
-
MySQL の AUTO_INCREMENT とは何ですか?
- AUTO_INCREMENT は、テーブル內(nèi)の新しいレコードの一意の識(shí)別子を自動(dòng)的に生成する MySQL の機(jī)能で、主キー列によく使用されます。
-
SQL の JOIN 句とは何ですか?
- JOIN は、関連する列に基づいて 2 つ以上のテーブルの行を結(jié)合するために使用されます。タイプには、INNER JOIN、LEFT JOIN、RIGHT JOIN、FULL JOIN があります。
-
INNER JOIN とは何ですか?
- INNER JOIN は、結(jié)合される両方のテーブルで一致する値を持つ行のみを返します。
-
左結(jié)合とは何ですか?
- LEFT JOIN は、左側(cè)のテーブルからすべての行を返し、右側(cè)のテーブルから一致した行を返します。一致するものが見つからない場(chǎng)合は、右側(cè)のテーブルの列に対して NULL 値が返されます。
-
SQL の UNION とは何ですか?
- UNION は、2 つ以上の SELECT クエリの結(jié)果セットを結(jié)合し、クエリ間の重複行を削除します。すべての SELECT ステートメントの列は、同じ番號(hào)とデータ型を持つ必要があります。
-
UNION と UNION ALL の違いは何ですか?
- UNION は重複した行を削除しますが、UNION ALL は結(jié)合された結(jié)果セットからすべての重複を含みます。
-
GROUP BY 句とは何ですか?
- GROUP BY は、同じ?jìng)帳虺证男肖蚣?jì)行にグループ化し、SUM()、AVG()、COUNT()、MIN()、MAX() などの集計(jì)関數(shù)でよく使用されます。
B. 中級(jí)レベルの MySQL の質(zhì)問(wèn):
-
MySQL のインデックスとは何ですか?
- インデックスは、テーブルのデータ取得操作の速度を向上させるデータ構(gòu)造です。テーブル全體をスキャンせずにデータをすばやく見つけるために使用されます。
-
MySQL のインデックスにはどのような種類がありますか?
- MySQL の一般的なインデックス タイプには次のものがあります。
- 主インデックス: 主キーに対して自動(dòng)的に作成されます。
- 一意のインデックス: インデックス付き列內(nèi)のすべての値が一意であることを保証します。
- 全文インデックス: テキスト検索に使用されます。
- 複合インデックス: 複數(shù)の列のインデックス。
- MySQL の一般的なインデックス タイプには次のものがあります。
-
正規(guī)化とは何ですか?
- Normalization is the process of organizing database tables to reduce redundancy and improve data integrity. It involves dividing large tables into smaller, related tables.
-
What is denormalization?
- Denormalization is the process of combining tables to reduce the number of joins and improve query performance, often used in read-heavy applications.
-
What is the HAVING clause?
- HAVING is used to filter records after an aggregation is applied, typically with GROUP BY. It is similar to WHERE, but WHERE is applied before aggregation.
-
What is a stored procedure?
- A stored procedure is a set of SQL statements that can be executed as a single unit. It is stored in the database and can be called with a specific name, often used to encapsulate complex logic.
-
What is a trigger in MySQL?
- A trigger is a set of SQL statements that automatically executes when a specified event (INSERT, UPDATE, DELETE) occurs on a table.
-
What is a view in MySQL?
- A view is a virtual table that is based on the result of a SELECT query. It does not store data physically but provides a way to simplify complex queries.
-
What is a transaction in MySQL?
- A transaction is a sequence of SQL statements that are executed as a single unit of work. It follows ACID properties (Atomicity, Consistency, Isolation, Durability).
-
What are ACID properties?
- Atomicity: All operations within a transaction are completed or none are.
- Consistency: Transactions bring the database from one valid state to another.
- Isolation: Transactions do not interfere with each other.
- Durability: Once a transaction is committed, changes are permanent.
C. Advanced-Level MySQL Questions:
-
What is replication in MySQL?
- Replication is the process of copying data from one MySQL server (master) to one or more servers (slaves) for redundancy and load balancing.
-
What are the different types of replication in MySQL?
- Master-Slave Replication: Data is written to the master and replicated to slaves.
- Master-Master Replication: Both servers can act as master and replicate data to each other.
- Group Replication: Multi-master replication for highly available MySQL clusters.
-
What is the InnoDB storage engine?
- InnoDB is the default storage engine in MySQL, providing support for ACID-compliant transactions, foreign keys, and crash recovery.
-
What is the difference between DELETE, TRUNCATE, and DROP?
- DELETE: Removes rows from a table based on a condition. It can be rolled back.
- TRUNCATE: Removes all rows from a table but retains its structure. It cannot be rolled back.
- DROP: Deletes the entire table, including its structure. It cannot be rolled back.
-
How do you optimize a slow query in MySQL?
- Techniques include using proper indexing, analyzing query execution plans (EXPLAIN), rewriting queries for efficiency, using JOIN instead of subqueries, avoiding SELECT *, and ensuring hardware resources are adequate.
The above is the detailed content of COMMON MYSQL INTERVIEW QUESTIONS. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

TosecurelyconnecttoaremoteMySQLserver,useSSHtunneling,configureMySQLforremoteaccess,setfirewallrules,andconsiderSSLencryption.First,establishanSSHtunnelwithssh-L3307:localhost:3306user@remote-server-Nandconnectviamysql-h127.0.0.1-P3307.Second,editMyS

ForeignkeysinMySQLensuredataintegritybyenforcingrelationshipsbetweentables.Theypreventorphanedrecords,restrictinvaliddataentry,andcancascadechangesautomatically.BothtablesmustusetheInnoDBstorageengine,andforeignkeycolumnsmustmatchthedatatypeoftherefe

mysqldump is a common tool for performing logical backups of MySQL databases. It generates SQL files containing CREATE and INSERT statements to rebuild the database. 1. It does not back up the original file, but converts the database structure and content into portable SQL commands; 2. It is suitable for small databases or selective recovery, and is not suitable for fast recovery of TB-level data; 3. Common options include --single-transaction, --databases, --all-databases, --routines, etc.; 4. Use mysql command to import during recovery, and can turn off foreign key checks to improve speed; 5. It is recommended to test backup regularly, use compression, and automatic adjustment.

Turn on MySQL slow query logs and analyze locationable performance issues. 1. Edit the configuration file or dynamically set slow_query_log and long_query_time; 2. The log contains key fields such as Query_time, Lock_time, Rows_examined to assist in judging efficiency bottlenecks; 3. Use mysqldumpslow or pt-query-digest tools to efficiently analyze logs; 4. Optimization suggestions include adding indexes, avoiding SELECT*, splitting complex queries, etc. For example, adding an index to user_id can significantly reduce the number of scanned rows and improve query efficiency.

When handling NULL values ??in MySQL, please note: 1. When designing the table, the key fields are set to NOTNULL, and optional fields are allowed NULL; 2. ISNULL or ISNOTNULL must be used with = or !=; 3. IFNULL or COALESCE functions can be used to replace the display default values; 4. Be cautious when using NULL values ??directly when inserting or updating, and pay attention to the data source and ORM framework processing methods. NULL represents an unknown value and does not equal any value, including itself. Therefore, be careful when querying, counting, and connecting tables to avoid missing data or logical errors. Rational use of functions and constraints can effectively reduce interference caused by NULL.

To reset the root password of MySQL, please follow the following steps: 1. Stop the MySQL server, use sudosystemctlstopmysql or sudosystemctlstopmysqld; 2. Start MySQL in --skip-grant-tables mode, execute sudomysqld-skip-grant-tables&; 3. Log in to MySQL and execute the corresponding SQL command to modify the password according to the version, such as FLUSHPRIVILEGES;ALTERUSER'root'@'localhost'IDENTIFIEDBY'your_new

To view the size of the MySQL database and table, you can query the information_schema directly or use the command line tool. 1. Check the entire database size: Execute the SQL statement SELECTtable_schemaAS'Database',SUM(data_length index_length)/1024/1024AS'Size(MB)'FROMinformation_schema.tablesGROUPBYtable_schema; you can get the total size of all databases, or add WHERE conditions to limit the specific database; 2. Check the single table size: use SELECTta

Character set and sorting rules issues are common when cross-platform migration or multi-person development, resulting in garbled code or inconsistent query. There are three core solutions: First, check and unify the character set of database, table, and fields to utf8mb4, view through SHOWCREATEDATABASE/TABLE, and modify it with ALTER statement; second, specify the utf8mb4 character set when the client connects, and set it in connection parameters or execute SETNAMES; third, select the sorting rules reasonably, and recommend using utf8mb4_unicode_ci to ensure the accuracy of comparison and sorting, and specify or modify it through ALTER when building the library and table.
