Common interview questions for MySQL

Source: Internet
Author: User
Tags numeric value rollback

  1. 1. How to log in to MySQL database
  2. Mysql-u username-p
  3. 2. How to turn on/off MySQL service
  4. Service MySQL Start/stop
  5. 3. Check the status of MySQL
  6. Service MySQL Status
  7. 4, how to display the number of all databases
  8. Show databases
  9. 5. How to get the names and types of all field objects in a table
  10. Describe table_name;
  11. 6. Does MySQL support business?
  12. In the default mode, MySQL is autocommit mode, all database update operations are committed immediately, so by default, MySQL does not support transactions.
  13. But if your MySQL table type is using InnoDB Tables or BDB Tables, your MySQL can use transaction processing, using Set autocommit=0 can allow MySQL to be allowed in non-autocommit mode, In non-autocommit mode, you must use commit to commit your changes, or roll back your changes with rollback.
  14. Examples are as follows:
  15. START TRANSACTION;
  16. SELECT @a:=sum (Salary) from table1 WHERE type=1;
  17. UPDATE table2 SET [email protected] WHERE type=1;
  18. COMMIT;
  19. 7. What are the characteristics of MySQL compared to other databases?
  20. MySQL is a small relational database management system, the developer for the Swedish MySQL AB company, has now been acquired by Sun, support FreeBSD, Linux, MAC, Windows and other large databases such as Oracle, DB2, SQL Server is slightly weaker than the function
  21. 1. Can handle large data with thousands records
  22. 2. Support Common SQL statement specification
  23. 3, portable row height, easy installation and small
  24. 4, good operating efficiency, rich information network support
  25. 5, debugging, management, optimization simple (relative to other large databases)
  26. 8. The difference between varchar and char
  27. Char is a fixed-length type, and varchar is a variable-length type
  28. 9. What kinds of database things are there?
  29. Isolation, durability, consistency, atomicity
  30. 10. Please briefly describe the four types of transaction isolation level names supported by InnoDB in MySQL, and the difference between the levels.
  31. The four isolation levels defined by the SQL standard are:
  32. Read uncommited: Reading uncommitted content
  33. Read Committed: Reading submissions
  34. REPEATABLE READ: Can be reread
  35. Serializable: Serializable
  36. Detailed explanations are as follows:
  37. READ UNCOMMITTED (Read UNCOMMITTED content)
  38. At this isolation level, all transactions can see the execution results of other uncommitted transactions. This isolation level is rarely used in real-world applications because it has no better performance than other levels. Reading uncommitted data is also known as Dirty reading (Dirty read).
  39. Read Committed (read submit content)
  40. This is the default isolation level for most database systems (but not MySQL default). It satisfies the simple definition of isolation: A transaction can only see changes that have been submitted to the firm. This isolation level also supports so-called non-repeatable reads (nonrepeatable read), because other instances of the same transaction may have new commits during the instance processing, so the same select may return different results.
  41. Repeatable Read (can be reread)
  42. This is the default transaction isolation level for MySQL, which ensures that multiple instances of the same transaction will see the same rows of data while concurrently reading the data. In theory, however, this can lead to another tricky problem: Phantom Reading (Phantom read). To put it simply, Phantom reads when a user reads a range of data rows, another transaction inserts a new row within that range, and when the user reads the data row of that range, a new phantom row is found. The InnoDB and Falcon storage engines address this issue through a multi-version concurrency control (mvcc,multiversion Concurrency control gap Lock) mechanism. Note: In fact, multi-version only solves the non-repeatable reading problem, and the gap lock (which is what it calls concurrency control) solves the Phantom reading problem.
  43. Serializable (Serializable)
  44. This is the highest isolation level, which solves the Phantom reading problem by forcing transactions to sort, making it impossible to conflict with one another. In short, it is a shared lock on every data row read. At this level, a large number of timeouts and lock competitions can result.
  45. For different transactions, different isolation levels are used to separate the results. Different isolation levels have different phenomena. There are 3 main types now:
  46. 1. Dirty reads (dirty read): One transaction can read another modified data that has not yet committed a transaction.
  47. 2, non-repeating read (nonrepeatable read): In the same transaction, the same query reads a row at T1 time, the data in this row is modified, it may be updated (update), or deleted (delete) when the line is re-read at T2 time.
  48. 3, Phantom Read (Phantom Read): In the same transaction, the same query is repeated multiple times, due to the other insert operation (insert) of the transaction commits, resulting in a different result set is returned each time.
  49. Different isolation levels have different phenomena, and there are different locking/concurrency mechanisms, the higher the isolation level, the worse the concurrency of the database, the 4 kinds of transaction isolation levels are shown in the following table:
  50. 12. What are the MySQL tables for permissions?
  51. The MySQL server controls user access to the database through a permission table, which 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, respectively. The structure and contents of these tables are described below:
  52. User Permission table: records the users account information that is allowed to connect to the server, and the permissions are global-level.
  53. DB Permission table: Records the operation permissions of each account on each database.
  54. Table_priv Permissions table: Records operation permissions at the data table level.
  55. Columns_priv Permissions table: Records the operation permissions at the data column level.
  56. Host permission table: The database-level operation permissions on a given host are controlled more carefully with the DB permission table. This permission table is not affected by the grant and REVOKE statements.
  57. 13. What is the MySQL storage engine? How do I modify the MySQL storage engine?
  58. MyISAM Indexed sequential access method (indexed sequential access methods)
  59. MyISAM has most of the tools for checking and repairing tables. Tables can be compressed and supported for full-text collection
  60. is not a transactional security and does not support foreign keys.
  61. Memory is also the previous (HEAP) the type table is stored in RAM and the index of the table is hash distributed.
  62. Merge These tables use the MyISAM table collection as a single table for querying purposes, so you can avoid the maximum file size limit in some operating systems.
  63. Archive This type of table is supported only, insert, select does not support Delete,update,replace, and does not use indexes.
  64. CSV These tables are stored in a single file on the server, which contains data separated by commas.
  65. InnoDB This table is transaction-safe. Provides a commit (commit) rollback (substantive rollback) support for foreign keys, slower than MyISAM.
  66. Modify the MySQL storage engine ALTER TABLE tablename type = InnoDB;
  67. 14. MYSQL data table repair and data recovery surface questions
  68. 1. What is the condition of MySQL data sheet easily damaged?
  69. A sudden power outage in the server caused data file corruption.
  70. Force shutdown, without first shutting down the MySQL service and so on.
  71. 2. What is the main phenomenon after the data sheet is damaged?
  72. When you select data from a table, you get the following error: Incorrect key file for table: ' ... '. Try to repair it
  73. A query cannot find rows in a table or return incomplete data.
  74. Error:table ' P ' is marked as crashed and should be repaired.
  75. Failed to open table: Can ' t open file: ' xxx. MYI ' (errno:145).
  76. 3. What are the ways to repair a damaged data sheet?
  77. Use Myisamchk to fix the steps:
  78. 1) Stop the MySQL service before repairing.
  79. 2) Open the command line and go to the MySQL/bin directory.
  80. 3) Execute the path of the Myisamchk–recover database/*. MYI
  81. Use the REPAIR table or the OPTIMIZE table command to repair, REPAIR table table_name repair tables OPTIMIZE A table table_name optimize tables for the repair of corrupted tables.
  82. OPTIMIZE table is used to reclaim unused database space, and when the data rows on the table are deleted, the disk space occupied is not immediately reclaimed, the space is reclaimed after the OPTIMIZE Table command is used, and the data rows on the disk are re-ordered (note: on disk, Rather than a database)
  83. 15. What are the methods commands for the performance analysis of MySQL database server?
  84. Show status
  85. Some variable values worth monitoring:
  86. Bytes_received and Bytes_sent
  87. Traffic to and from the server.
  88. Com_* the command that the server is executing.
  89. Created_* temporary tables and files that are created between query execution periods.
  90. handler_* Storage engine operation.
  91. select_* different types of join execution plans.
  92. Sort_* several sorts of information.
  93. Show session status like ' Select ';
  94. Show Profiles
  95. SET profiling=1;
  96. Show Profiles\g
  97. Show profile;
  98. 16, MySQL record currency with what field type good
  99. The numeric and decimal types are implemented by MySQL as the same type, which is allowed in the SQL92 standard. They are used to hold values, and the exact accuracy of the value is an extremely important value, such as money-related data. When declaring a class is a moment of these types, the accuracy and scale of the energy can be (and is usually) specified;
  100. For example:
  101. Salary DECIMAL (9,2)
  102. In this example, 9 (precision) represents the total number of decimal places that will be used to store the value, while a 2 (scale) represents the number of digits that will be used to store the decimal point. Therefore, in this case, the values that can be stored in the Salary column range from 9999999.99 to 9999999.99. In Ansi/iso SQL92, syntactic decimal (p) is equivalent to decimal (p,0). Similarly, the syntactic 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 variant forms of the Decimal/numeric data type. This is generally not a serious problem, since the main benefits of these types are derived from the ability to control precision and scale clearly.
  103. The decimal and numeric values are stored as strings, not as binary floating-point numbers, so that the decimal precision of those values is saved. One character is used for each digit of the value, the decimal point (if scale>0), and the "-" symbol (for negative values). If scale is 0,decimal and the numeric value does not contain a decimal point or fractional part.
  104. Decimal and numeric are worth the largest range as a double, but for a given decimal or numeric column, the actual range can be limited by the precision or scale of the given column. When such a column is assigned to a bit that is later than the decimal point, the value is rounded up according to scale. When a decimal or numeric column is assigned a value whose size exceeds the implied range of the specified (or default) precision and scale, the MySQL store represents the corresponding endpoint value for that range.

Common interview questions for MySQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.