MySQL database standardization design (1) _ MySQL

Source: Internet
Author: User
MySQL database standardization design (1) establish a database table maintenance specification
It is a good idea to perform a database table check on a regular basis rather than when a problem occurs. Taking into account the establishment of a schedule for preventive maintenance to assist with automatic problems, you can take measures to correct them:

Perform regular database backup and allow log updates.

Schedule regular table checks. Using the checklist will reduce the chances of using backup. This job is easy to implement by using scheduled tasks in Windows and cron jobs in Unix (usually called from the crontab file of this account as shown in the running server.

For example, if you run the server as a mysql user, you can create a regular check from the mysql crontab file. If you do not know how to use cron, use the following command to view the relevant Unix manual page:

$ Man cron
$ Man crontab

The database table is checked during system boot before the server is started. And it may be restarted due to an early crash. If this is the case, the database table may have been destroyed and should be thoroughly checked.

Create a script for regular maintenance

To run an automatic table check, you can write a script to change the directory to the server data directory and perform myisamchk and isamchk on all database tables. If you only have a MyISAM table or an ISAM table, you only need one program. you can comment out the unrelated program from the script.

This tutorial can be called by cron or during system startup.

For maintenance purposes, you can use myisamchk-s to check the table. The-s, -- silent option enables myisamchk and isamchk to run in silent mode. only messages are printed when an error occurs. In addition, myisamchk supports the -- fast option, which allows the program to skip people and tables that have not been modified since the last check.

1. a simple script

For example, a simple script that is easy to understand checks all tables in the server directory (DATADIR should be changed to the appropriate value for your system ):

#! /Bin/sh
Cd DATADIR

Myisamchk -- silent -- fast */*. MYIi

Samchk -- silent */*. ISM

2. a complicated script

A potential problem with this script: if there are many tables, the wildcard mode '*/*. myi' and '*/*. ISM 'may be unavailable because "too has arguments (too many parameters)" or the command line exceeds the length allowed by shell. The script can be further modified to (similarly, DATADIR is modified to a value suitable for your system ):

#! /Bin/sh
Datadir = DATADIR

Find $ dtatdir

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.