MySQL must know must know the study notes Chapter 29 database maintenance

MySQL database is a disk-based file. Ordinary backup systems and routines can back up MySQL data, but these files are always open and in use. Ordinary file backups are not always effective.

Backup method:
1. Use mysqldump to dump the contents of all databases to an external file. This application should be run before performing regular backups in order to properly backup the dump file.
2. Use mysqlhotcopy to copy all data from a database, not all database engines support it).
3. Use BACKUP TABLE or SELECT INTO OUTFILE to dump all data to an external file. Both statements accept the name of the system file to be created. This system file must not exist, otherwise an error will occur. Can be restored with RESTORE TABLE.

To ensure that all data is written to disk (including indexes), you need to use the FLUSH TABLES statement before backup.

Analyze and save the distribution of the index.:

ANALYZE TABLE orders;

Run it:
Insert picture description here

In the process of analyzing a table with ANALYZE TABLE, the database system will add a read-only lock to the table. During the analysis, you can only read the records in the table, not update and insert records. The ANALYZE TABLE statement can analyze tables whose engines are InnoDB and MyISAM.

Discover and repair table problems:

CHECK TABLE orders, orderitems;

Run it:
Insert picture description here
CHECK TABLE also checks indexes on MyISAM tables. It also supports some check methods for MyISAM tables:
1. CHECKED checks the tables that have been changed since the last check.
2. EXTENDED performs the most thorough inspection.
3. FAST checks for tables that were not closed normally.
4. MEDIUM checks all deleted links and performs key verification.
5. QUICK only performs a quick scan.

If MyISAM access produces incorrect or inconsistent results, REPAIR TABLE may be required to repair the corresponding table. This statement cannot be used frequently, otherwise it will cause greater problems.

If you delete a large amount of data from a table, you should use OPTIMIZE TABLE to reclaim the space used to optimize table performance.

Server startup problems usually occur when the MySQL configuration or the server itself is changed. MySQL reports errors when the problem occurs. However, most MySQL servers are automatically started as system processes or services, and these messages may not be seen.

When troubleshooting system startup problems, you should try to manually start the server, which can be started by the mysqld command. The following are several important mysqld command line options:
1. --help: Display a list of options.
2. --safe-mode: load the server minus some of the best configuration.
3. –verbose: Display full text messages.
4. –version: Display version information.

The mysql log storage location can be viewed with the following command:

show variables like 'datadir';

Main log files:
1. Error log: contains the details of startup and shutdown problems and any errors. The log name is usually hostnamt.err. The log name can be changed with the -log-error command line option.
2. Query log: record all MySQL activities, it will quickly become very large, it should not be used for a long time, it is very useful in diagnosing problems, the log name is usually hostname.err, this log name can be changed with the -log command line option .
3. Binary log: record all statements that may have updated data. The log name is usually hostname-bin, and the log name can be changed with the -log-bin command line option. This log is added in MySQL 5. The previous version used the update log.
4. Slow query log: It is useful to record any slow-executing queries and determine where the database needs to be optimized. The log name is usually hostname-slow.log, and the log name can be changed with the -log-slow-queries command line option.

When using the log, you can use the FLUSH LOGS statement to refresh and restart all log files (that is, close the currently used log file, open a new one, log file number +1).

Guess you like

Origin blog.csdn.net/tus00000/article/details/111872021