阿里云服务器上装有MySQL 5.6,这几天MySQL服务经常死掉,启动MySQL服务(service mysql start),却报如下错误
Starting MySQL.. ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).
简单的去搜索一下关于此错误的解决方法,找到一个说删除InnoDB表的日志文件即可,于是就尝试了一下(删除操作首先别忘了备份)
不知道mysql数据存放位置的可以这样子查看,找到my.cnf,里面的datadir=/var/lib/mysql既是了
cat /etc/my.cnf 找到mysql数据存放位置
来到这里面有三个文件ibdata1,ib_logfile0,ib_logfile1
其中ibdata1是InnoDB表的共享表空间,切忌不可以删除这个文件,部分InnoDB表的数据就在里面呢
ib_logfile0,ib_logfile1,这两个文件不同配置下名字会不同,是InnoDB表的日志文件(别忘记了InnoDB表示事务安全的,当数据库奔溃时,重启数据库服务,会根据这些日志文件重做一些事务)
删除了这两个日志文件,然后启动mysql(service mysql start)这次启动成功了!
--------------------------------------------------------------------------------------------------------
可是过了不久,真的不久,才十几分钟,数据库又挂了,启动数据库(service mysql start),又报下面这个错误
Starting MySQL.. ERROR! The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid).
然后再次删除日志文件,再启动,可以了,再过了不久……又挂了,所以明白,问题不出于这里
这些问题,每个人出错的都不一样,网上别人的出错原因也许和你不一样呢,要不人家可以解决,你怎么就不可以解决,故去查看msyql错误记录文件自己瞧个明白
msyql错误记录文件不知道在哪里,可以这样子来找:同样查看my.cnf文件,其中mysqld-safe下的log-error就是mysql错误日志
[mysqld_safe]
log-error=/var/log/mysqld.log
打开它看看,发现一堆错误,用这个命令简单看一下出错重点
cat /var/log/mysqld.log | grep 'ERROR' | less
发现了服务启动时,为何会跑错了
2013-08-04 13:48:22 760 [ERROR] InnoDB: Attempted to open a previously opened tablespace. Previous tablespace em/temp uses space ID: 2 at filepath: ./em/temp.ibd. Cannot open tablespace mysql/innodb_index_stats which uses space ID: 2 at filepath: ./mysql/innodb_index_stats.ibd
打开表空间出错!!出这个错的原因是以前有次操作把ibdata1给删除掉了!(ibdata1文件刚才说了,共享表空间!!删除掉了后mysql虽然会重新生成,但是已经损坏了所有的InnoDB数据库了。ps:为什么会删除掉这个文件,我也不知道是什么时候删除了,是通过history看到的)
找到原因了,但是ibdata1这个文件没有备份,恢复不了,还在我这个服务上的数据库都是测试数据,可以drop掉重新导入以前备份的版本,故drop掉损坏的数据库,在mysql命令中是drop不掉的,只能在文件系统里直接删除其文件(第一步已经知道了数据存储位置了,直接删(ps记得先备份))
然后再重建了数据库,导入数据,重启mysql,正常启动,过了一天还没有挂掉!修复成功!第二天再去看一下mysql错误日志,又有了新发现
--------------------------------------------------------------------------------------------------------------
tail -n 200 /var/log/mysqld.log
文件里都在报这样的错误
Error: Table "mysql"."innodb_table_stats" not found.
2013-04-02 09:07:35 7fc53f5e4700 InnoDB: Recalculation of persistent statistics requested for table "mydatabase"."mytable" but the required persistent statistics storage is not present or is corrupted. Using transient stats instead.
但是目前有没察觉到对项目和数据库使用的明显影响,但是还要解决的,这篇博客说的很明白,果断推荐
http://hi.baidu.com/life_to_you/item/d35894c0058a993098b498ee
最后,都没发现什么问题了。MySQL遇到什么问题,第一下还是看下mysql的错误日志比较好,里面记录的一清二楚,逐个排除就好啦

MySQLstringtypesimpactstorageandperformanceasfollows:1)CHARisfixed-length,alwaysusingthesamestoragespace,whichcanbefasterbutlessspace-efficient.2)VARCHARisvariable-length,morespace-efficientbutpotentiallyslower.3)TEXTisforlargetext,storedoutsiderows,

MySQLstringtypesincludeVARCHAR,TEXT,CHAR,ENUM,andSET.1)VARCHARisversatileforvariable-lengthstringsuptoaspecifiedlimit.2)TEXTisidealforlargetextstoragewithoutadefinedlength.3)CHARisfixed-length,suitableforconsistentdatalikecodes.4)ENUMenforcesdatainte

MySQLoffersvariousstringdatatypes:1)CHARforfixed-lengthstrings,2)VARCHARforvariable-lengthtext,3)BINARYandVARBINARYforbinarydata,4)BLOBandTEXTforlargedata,and5)ENUMandSETforcontrolledinput.Eachtypehasspecificusesandperformancecharacteristics,sochoose

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

ToaddusersinMySQLeffectivelyandsecurely,followthesesteps:1)UsetheCREATEUSERstatementtoaddanewuser,specifyingthehostandastrongpassword.2)GrantnecessaryprivilegesusingtheGRANTstatement,adheringtotheprincipleofleastprivilege.3)Implementsecuritymeasuresl

ToaddanewuserwithcomplexpermissionsinMySQL,followthesesteps:1)CreatetheuserwithCREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';.2)Grantreadaccesstoalltablesin'mydatabase'withGRANTSELECTONmydatabase.TO'newuser'@'localhost';.3)Grantwriteaccessto'

The string data types in MySQL include CHAR, VARCHAR, BINARY, VARBINARY, BLOB, and TEXT. The collations determine the comparison and sorting of strings. 1.CHAR is suitable for fixed-length strings, VARCHAR is suitable for variable-length strings. 2.BINARY and VARBINARY are used for binary data, and BLOB and TEXT are used for large object data. 3. Sorting rules such as utf8mb4_unicode_ci ignores upper and lower case and is suitable for user names; utf8mb4_bin is case sensitive and is suitable for fields that require precise comparison.

The best MySQLVARCHAR column length selection should be based on data analysis, consider future growth, evaluate performance impacts, and character set requirements. 1) Analyze the data to determine typical lengths; 2) Reserve future expansion space; 3) Pay attention to the impact of large lengths on performance; 4) Consider the impact of character sets on storage. Through these steps, the efficiency and scalability of the database can be optimized.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
