[General] Basic Computer Classic Interview Questions Day 3

[General] Basic Computer Classic Interview Questions Day 3

1. Please explain the two main engines of mysql

MySQL has multiple storage engines, but the two most common main engines are InnoDB and MyISAM.

2. Let’s talk about the usage scenarios of the two mysql engines.

MySQL's two main engines, InnoDB and MyISAM, are each suitable for different usage scenarios. The following are their main uses and suitable application scenarios:

  1. InnoDB engine:
  • Transaction support: InnoDB is MySQL's default transaction storage engine, so it is very suitable for applications that require transaction support, such as e-commerce websites, banking systems, order processing systems, etc. It ensures data consistency and integrity, as well as transaction atomicity, consistency, isolation, and durability (ACID properties).
  • High concurrency performance: InnoDB supports row-level locking, which allows multiple concurrent users to access different rows of the same table at the same time, thus improving concurrency performance. This is important for applications with a large number of simultaneous online users.
  • Foreign key constraints: If your database needs to maintain relationships and referential integrity between tables, InnoDB is a better choice as it supports foreign key constraints.

Suitable application scenarios:

  • transactional applications
  • Highly concurrent read and write operations
  • Applications that require foreign key support
  • Applications with high data integrity and consistency requirements
  1. MyISAM engine:
  • Read-intensive applications: MyISAM performs quite well when handling large amounts of read operations. Because it uses table-level locking, it is suitable for read-intensive applications such as blogs, news websites, data warehouses, etc. when there are few concurrent write operations.
  • Transaction support not required: MyISAM does not support transactions, so it may be considered for applications that do not require ACID properties. If data consistency and integrity are not critical issues for the application, and performance is a primary concern, MyISAM may be an option.
  • Temporary tables: MyISAM is often used to create temporary tables for storing intermediate results or caching data.

Suitable application scenarios:

  • read-intensive applications
  • Simple query and report generation
  • Applications that do not require transaction support
  • Temporary tables and cache requirements

3. What do you think about the optimization methods of mysql?

  1. Appropriate index design :
  • Creating appropriate indexes can greatly improve query performance. Make sure the fields in your table are well chosen and planned so that indexes are used in common queries.
  1. Query optimization :
  • Use appropriate SQL queries, avoid using SELECT *, select only the required columns, and minimize data transfer.
  • Use EXPLAIN to analyze the query execution plan in order to optimize the query.
  1. Hardware optimization :
  • Use high-performance hardware, including fast disks, large memory, and multi-core processors, to improve database server performance.
  • Use SSD to accelerate disk I/O operations to reduce read and write latency.
  1. Adjust the buffer :
  • Adjust MySQL's buffer parameters, such as buffer pool size, query cache, etc., to ensure that data is well managed and accessed in memory.
  1. Partitions and sub-tables :
  • For large tables, you can consider partitioning or sub-tables to split the data into smaller parts to improve query performance.
  1. Regular maintenance :
  • Perform regular database maintenance, including optimizing tables, rebuilding indexes, and cleaning up data that is no longer used, to maintain database performance.
  1. Use a suitable storage engine :
  • Choose the appropriate storage engine, such as InnoDB or MyISAM, based on application needs to meet transactional or read-write needs.
  1. Distributed architecture :
  • For high-load applications, consider a distributed database architecture such as MySQL Cluster or sharding to achieve horizontal scalability.
  1. Query cache and caching layer :
  • Use a query cache or caching layer such as Memcached or Redis to reduce the load on the database server.
  1. Monitoring and log analysis :
  • Use monitoring tools and log analysis to track database performance and identify and resolve issues promptly.
  1. SQL optimizer tips :
  • Use SQL_HINTS to instruct the MySQL optimizer to execute queries. This can be achieved through index hints, query cache hints, etc.
  1. Connection pool management :
  • Use connection pooling to manage database connections to reduce connection overhead and improve concurrency performance.
  1. Optimize table structure :
  • Consider using appropriate data types, avoiding NULL values, and normalizing data to reduce data storage and improve query performance.
  1. Backup and recovery strategy :
  • Establish an effective backup and recovery strategy to prevent data loss or hardware failure.

4. What query conditions will cause the index to become invalid?

  1. Using functions or expressions : If functions or expressions are used in query conditions, it will usually cause index failure. For example, WHERE YEAR(date_column) = 2023this would invalidate the index because the database cannot use the index directly to look up the year.
  2. Type conversion is performed on the index column : If the type conversion is performed on the index column in the query, such as forcing an integer column to a character column, the index may become invalid.
  3. Using wildcards at the beginning of index columns for fuzzy searches : When wildcards (such as ) are used at the beginning of index columns LIKE '%keyword', the index is often not used efficiently. A wildcard at the beginning will invalidate the index because the database cannot locate the match quickly.
  4. Use the NOT operator : NOTWhen using the operator to negate query conditions, the index may become invalid. For example, WHERE NOT column_name = 'value'.
  5. Use the OR operator : When using ORthe operator to connect multiple conditions, if one of the conditions cannot use the index, the entire query may cause the index to fail.
  6. Use the inequality operator (!= or <>) : In some cases, filtering using the inequality operator can cause index failure, especially when the inequality operator covers a large portion of the data.
  7. Uneven data distribution : If the data is unevenly distributed across the index columns, that is, some values ​​appear very frequently and other values ​​occur rarely, then the index may not be used for frequently occurring values.
  8. Index columns participate in calculations : If the conditions in the query involve calculations on index columns, the index may become invalid. For example, WHERE column1 * 2 = 10.
  9. Table is too small : For very small tables, using indexes may not provide a significant performance gain because the database engine may choose a full table scan to fetch the data faster.
  10. Data type mismatch : If the data type in the query condition does not match the data type of the indexed column, the index may fail.

5. Let’s talk about the index classification of mysql

  1. B-tree Index :
  • B-tree index is the most common index type in MySQL, and it is also the default index type.
  • It works for equality queries, range queries, and sort operations.
  • B-tree indexes are suitable for most data types, including numbers, strings, and dates.
  • The default index type of the InnoDB storage engine is a B-tree index.
  1. Hash Index :
  • Hash indexes are suitable for equality queries, that is, they can only be used for exact matches.
  • It can provide very fast query speed in certain scenarios, but it is not suitable for range queries or sorting operations.
  • Hash indexes are usually used in the Memory storage engine and do not support persistent storage.
  1. Full-Text Index (Full-Text Index) :
  • Full-text indexing is suitable for text data and is used to realize full-text search.
  • It can handle text fields containing words and supports advanced search and sorting functions.
  • Both MyISAM and InnoDB storage engines support full-text indexing, but MyISAM's full-text indexing function is more powerful.
  1. Spatial Index :
  • Spatial indexes are suitable for processing geospatial data, such as coordinate points, lines, areas, etc.
  • It supports spatial geometry operations such as containment, intersection, distance calculation, etc.
  • MySQL uses R-tree index to implement spatial index and supports InnoDB and MyISAM storage engines.
  1. Prefix Index :
  • A prefix index is an index created on the first N characters of a column, rather than the entire column.
  • It can be used to reduce the size of indexes and improve query performance, at the possible expense of precision.
  • Prefix indexes are often used to handle long text columns.
  1. Composite Index :
  • A composite index combines multiple columns into one index to support multi-column queries.
  • It can improve the performance of multi-column conditional queries, but it should be carefully designed to ensure the best performance.
  • The order of the composite index and which columns are selected is very important.
  1. Unique Index (Unique Index) :
  • A unique index ensures that the values ​​in the indexed column are unique and does not allow duplicate values.
  • Unique indexes can be used to implement primary key or unique constraints.
  • When inserting or updating data, MySQL checks the unique index to ensure the uniqueness of the data.
  1. Primary Key Index :
  • A primary key index is a special unique index that uniquely identifies each row in a table.
  • There can only be one primary key index per table, usually defined together with the primary key column.
  • The primary key index is the physical sort order of the table, so querying the primary key column is usually very efficient.

6. List several linux commands

  1. ls : List files and subdirectories in the current directory.
ls
  1. pwd : Displays the path of the current working directory.
pwd
  1. cd : Change the current directory.
cd /path/to/directory
  1. mkdir : Create a new directory.
mkdir new_directory
  1. touch : timestamp when a new file was created or updated.
touch filename
  1. cp : Copy a file or directory.
cp source_file destination
  1. mv : Move a file or rename a file.
mv old_name new_name
  1. rm : Delete a file or directory.
rm filename
  1. cat : Display the contents of a file.
cat filename
  1. less : View file contents page by page.
less filename
  1. head : Displays the first few lines of the file.
head -n 10 filename
  1. tail : Displays the last few lines of the file.
tail -n 10 filename
  1. grep : Search for text patterns in files.
grep pattern filename
  1. ps : Displays running processes.
ps aux
  1. kill : Terminate a running process.
kill process_id
  1. ifconfig : Display network interface information.
ifconfig
  1. ping : Tests the network connection to a remote host.
ping remote_host
  1. ssh : Remotely log in to another computer via the SSH protocol.
ssh username@hostname
  1. top : Displays system resource usage and running processes in real time.
top
  1. tar : Create or decompress an archive file (usually a .tar.gz or .tar.bz2 file).
tar -zxvf archive.tar.gz

7. The difference between > and >> in Linux, commonly used log viewing commands

In Linux, >and >>are special symbols used to redirect output, and they have the following differences:

  1. >
  • >Symbol is used to redirect the output of a command to a file. If the target file already exists, the original content will be overwritten.
  • For example: command > filewrite the output of the command to filea file named. If the file does not exist, a new file will be created. If the file already exists, the original contents will be cleared and new output will be written.

Example:

echo "Hello, World!" > output.txt

This creates a new file output.txtand writes the string "Hello, World!" into it.

  1. >>
  • >>symbol is also used to redirect the output of a command to a file, but unlike >if the target file already exists, >>new output is appended to the existing contents.
  • For example: command >> fileAppend the output of the command to filethe end of a file named .

Example:

echo "Appended text." >> output.txt

output.txtThis will append the text "Appended text." to the end of the existing file.

Commonly used commands to view logs:

  1. cat
  • catCommand is used to display the contents of a file. Can be used to view the contents of small files.

Example:

cat filename
  1. less
  • lessIt is a paging viewer that can be used to view large files page by page, while providing search and browse functions.

Example:

less filename

In less, you can use the arrow keys to scroll up and down, press /the key to search, and press qthe key to exit.

  1. tail
  • tailThe command is used to display the last few lines of the file, and the last 10 lines are displayed by default.

Example:

tail filenameb

-nThe number of lines to display can be specified using the option, e.g. tail -n 20 filenamewill show the last 20 lines.

  1. head
  • headThe command is used to display the first few lines of the file, and the first 10 lines are displayed by default.

Example:

head filename

-nThe number of lines to display can be specified using the option, e.g. head -n 20 filenamewill show the first 20 lines.

8. Tell me about your understanding of the scp command.

SCP (Secure Copy Protocol) is a command-line tool for securely copying files and directories between different systems. It is built on top of the SSH protocol, which provides data encryption and authentication, so data transmission is safe.

The basic syntax of the SCP command is as follows:

scp [options] source destination
  • source: The source path of the file or directory to be copied. Can be a local file system path or a file path on a remote host. If it is a remote path, it is usually user@host:source_pathspecified in the form, where useris the username on the remote host, hostis the hostname or IP address of the remote host, and source_pathis the path to the source file or directory.
  • destination: The target path for copying. Again, can be a local filesystem path or a path on a remote host. If it is a remote path, it is also user@host:destination_pathspecified in the form.

Common SCP options include:

  • -r: Recursive copy, used to copy directories and their contents.
  • -P:Specify the remote SSH port number.
  • -i: Specifies the private key file used for authentication.
  • -v: Enable verbose output for debugging purposes.

Some common uses of SCP include:

  1. To copy a file or directory from a local system to a remote host :
scp local_file user@remote_host:remote_path
  1. To copy a file or directory from a remote host to the local system :
scp user@remote_host:remote_file local_path
  1. Copy files or directories between remote hosts :
scp user1@remote_host1:source_path user2@remote_host2:destination_path
  1. Use a different SSH port number :
scp -P 2222 local_file user@remote_host:remote_path

9. Tell me about your understanding of the tar command.

tar(tape archive) is a commonly used command line tool for creating, viewing, extracting and compressing archives of files and directories in Unix and Linux systems. tarThe command is typically used to package multiple files and directories into a single file for backup, transfer, or archiving. Here is my tarunderstanding of the command:

tarThe basic syntax of the command is as follows:

tar [选项] [目标] []

Common taroptions include:

  • -c:Create a new archive file.
  • -x: Extract files from archive.
  • -t: List the files in the archive.
  • -f: Specify the name of the archive file.
  • -v: Display detailed information, usually used to display a list of extracted or created files.
  • -z: Use gzip for compression/decompression.
  • -j: Use bzip2 for compression/decompression.
  • -C: Specify the target directory when extracting files.

Some common tarcommand examples:

  1. Create archive :
tar -cvf archive.tar file1 file2 directory1

This will create archive.taran archive file named containing , file1, file2and directory1.

  1. Extract archive files :
tar -xvf archive.tar

This will archive.tarextract all files and directories from it.

  1. View the contents of the archive :
tar -tvf archive.tar

This will archive.tarlist the files in .

  1. Use gzip compression :
tar -czvf archive.tar.gz directory1

This will compress the pair using gzip directory1and create archive.tar.gzan archive named.

  1. Decompress a gzip-compressed archive :
tar -xzvf archive.tar.gz

This will unzip archive.tar.gzand extract the files inside.

tarThe commands are very useful and can be used for tasks such as backing up, migrating files, creating software distribution packages, and more. It is one of the standard tools in Unix and Linux systems, with rich options and features that can be configured according to your needs. For more details, you can view tarthe man page of the command using man tarthe command.

Guess you like

Origin blog.csdn.net/godnightshao/article/details/132796507