如何检测MySQL数据库表的故障
欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入 你可能在使用MySQL过程中,各种意外导致数据库表的损坏,而且这些数据往往是最新的数据,通常不可能在备份数据中找到。本文将讲述如何检测MySQL数据库表的故障。 表的故障检测和修正的一般过程如下:
欢迎进入Linux社区论坛,与200万技术人员互动交流 >>进入
你可能在使用MySQL过程中,各种意外导致数据库表的损坏,而且这些数据往往是最新的数据,通常不可能在备份数据中找到。本文将讲述如何检测MySQL数据库表的故障。
表的故障检测和修正的一般过程如下:
◆ 检查出错的表。如果该表检查通过,则完成任务,否则必须修复出错的数据库表。
◆ 在开始修复之前对表文件进行拷贝,以保证数据的安全。
◆ 开始修复数据库表。
◆ 如果修复失败,从数据库的备份或更新日志中恢复数据。
在使用myisamchk或isamchk检查或修复表之前,应该首先注意:
◆ 建立数据库备份和使用更新日志,以防修复失败,丢失数据。
◆ 仔细阅读本章内容以后再进行操作,尤其是不应该在阅读“避免与MySQL服务器交互作用”之前进行操作。因为,在你没有足够的知识之前贸然操作,可能会引起严重的后果。
◆ 如果你在Unix平台上对表进行维护时,应该首先注册到专用的帐户 mysql,以避免对表读写访问产生所有权的问题,以及破坏数据库目录的所有权限。
数据库表的维护工具
MySQL的myisanchk和isamchk实用程序很类似,基本上它们具有同样的使用方法。它们之间的主要区别时所使用的表的类型。为了检查 /修复MyISAM表(.MYI和.MYD),你应该使用myisamchk实用程序。为了检查/修复ISAM表(.ISM和.ISD),你应该使用 isamchk实用程序。
◆ 为了使用任一个使用程序,应指明你要检查或修复的表,myisamchk和isamchk的使用方法为:
shell>myisamchk options tbl_nameshell>isamchk options tbl_name
如果你愿意,你可以在命令行命名几个表。
◆ 你也能指定一个名字作为一个索引文件(用“ .MYI”或“.ISM”后缀),它允许你通过使用模式“*.MYI”或“.ISM”指定在一个目录所有的表。例如,如果你在一个数据库目录,你可以这样在目录下检查所有的表:
shell> myisamchk *.MYIshell>isamchk *.ISM
◆ 如果你不在数据库目录下,你可指定目录的路径:
shell> myisamchk options /path/to/database_dir/*.MYIshell> isamchk options /path/to/database_dir/*.ISM
◆ 你甚至可以通过为MySQL数据目录的路径指定一个通配符来作用于所有的数据库中的所有表:
shell> myisamchk options /path/to/datadir/*/*.MYIshell> isamchk options /path/to/database_dir/*/*.ISM
这个方法无法在windows平台下使用。
注意 不论是myisamchk还是isamchk都不对表所在的位置做任何判断,因此,应该或者在包含表文件的目录运行程序,或者指定表的路径名。这允许你将表文件拷贝到另一个目录中并用该拷贝进行操作。
检查数据库表
myisamchk和isamchk提供了表的检查方法,这些方法在彻底检查表的程度方面有差异。
标准的方法检查表
通常用标准的方法就足够了。对表使用标准的方法进行检查,不使用任何选项直接调用即可,或用-s或--silent选项的任何一个:
myisamchk tbl_nameisamchk tbl_name
这能找出所有错误的99.99%。它不能找出的是仅仅涉及数据文件的损坏(这很不常见)。
完全彻底的数据检查
为了执行扩充检查,使用--extend-check或-e选项,这个选项检查数据:
myisamchk -e tbl_nameisamchk -e tbl_name
它做一个完全彻底的数据检查(-e意思是“扩展检查”)。它对每一行做每个键的读检查以证实他们确实指向正确的行。这在一个有很多键的大表上可能花很长时间。myisamchk通常将在它发现第一个错误以后停止。如果你想要获得更多的信息,你能增加--verbose(-v)选项。这使得 myisamchk或isamchk继续一直到最多20个错误。在一般使用中,一个简单的标准检查(没有除表名以外的参数)就足够了。
中等程度的检查
指定选项--medium-check或-m
myisamchk -m tbl_name
中等程度的检查不如扩展检查彻底,但速度快一些。其意义不大,较少使用。
如果对于--extend-check检查不报告错误,则可以肯定表是完好的。如果你仍然感觉表有问题,那原因肯定在其它地方。应重新检查人和好像有问题的查询以验证查询是正确书写的。如果你认为问题可能是MySQL服务器的原因,应该考虑整理一份故障报告或者升级到新的版本上。
可能有用的检查选项:
1.-i或―information 打印统计信息,例如:
myisamchk -e -i tbl_name
象前面的命令一样,但是-i选项告诉myisamchk还打印出一些统计信息。
2.-C,--check-only-changed
只检查上一次检查后被修改的表。

Hot AI Tools

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

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

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

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



The key differences between CentOS and Ubuntu are: origin (CentOS originates from Red Hat, for enterprises; Ubuntu originates from Debian, for individuals), package management (CentOS uses yum, focusing on stability; Ubuntu uses apt, for high update frequency), support cycle (CentOS provides 10 years of support, Ubuntu provides 5 years of LTS support), community support (CentOS focuses on stability, Ubuntu provides a wide range of tutorials and documents), uses (CentOS is biased towards servers, Ubuntu is suitable for servers and desktops), other differences include installation simplicity (CentOS is thin)

CentOS will be shut down in 2024 because its upstream distribution, RHEL 8, has been shut down. This shutdown will affect the CentOS 8 system, preventing it from continuing to receive updates. Users should plan for migration, and recommended options include CentOS Stream, AlmaLinux, and Rocky Linux to keep the system safe and stable.

Docker uses Linux kernel features to provide an efficient and isolated application running environment. Its working principle is as follows: 1. The mirror is used as a read-only template, which contains everything you need to run the application; 2. The Union File System (UnionFS) stacks multiple file systems, only storing the differences, saving space and speeding up; 3. The daemon manages the mirrors and containers, and the client uses them for interaction; 4. Namespaces and cgroups implement container isolation and resource limitations; 5. Multiple network modes support container interconnection. Only by understanding these core concepts can you better utilize Docker.

CentOS installation steps: Download the ISO image and burn bootable media; boot and select the installation source; select the language and keyboard layout; configure the network; partition the hard disk; set the system clock; create the root user; select the software package; start the installation; restart and boot from the hard disk after the installation is completed.

How to use Docker Desktop? Docker Desktop is a tool for running Docker containers on local machines. The steps to use include: 1. Install Docker Desktop; 2. Start Docker Desktop; 3. Create Docker image (using Dockerfile); 4. Build Docker image (using docker build); 5. Run Docker container (using docker run).

Backup and Recovery Policy of GitLab under CentOS System In order to ensure data security and recoverability, GitLab on CentOS provides a variety of backup methods. This article will introduce several common backup methods, configuration parameters and recovery processes in detail to help you establish a complete GitLab backup and recovery strategy. 1. Manual backup Use the gitlab-rakegitlab:backup:create command to execute manual backup. This command backs up key information such as GitLab repository, database, users, user groups, keys, and permissions. The default backup file is stored in the /var/opt/gitlab/backups directory. You can modify /etc/gitlab

CentOS hard disk mount is divided into the following steps: determine the hard disk device name (/dev/sdX); create a mount point (it is recommended to use /mnt/newdisk); execute the mount command (mount /dev/sdX1 /mnt/newdisk); edit the /etc/fstab file to add a permanent mount configuration; use the umount command to uninstall the device to ensure that no process uses the device.

Docker LNMP container call steps: Run the container: docker run -d --name lnmp-container -p 80:80 -p 443:443 lnmp-stack to get the container IP: docker inspect lnmp-container | grep IPAddress access website: http://<Container IP>/index.phpSSH access: docker exec -it lnmp-container bash access MySQL: mysql -u roo
