MySQL错误集锦

前言

平时部署各种数据库会遇到很多错误,但是不去记录的话下次遇到头疼又要花很多时间去看博客看手册,非常浪费时间,这里把遇到的错误和解决过程做个记录

开始

故障一:
版本:mysql5.6

ERROR! MySQL server PID file could not be found!
Starting MySQL... ERROR! The server quit without updating PID file (/usr/local/mysql/data/data/localhost.localdomain.pid).

解决方式:重新初始化
先看一下配置文件
cat /etc/my.cnf

[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data/data
log-bin=/usr/local/mysql/data/binlog/mysql-bin
log-bin-index=/usr/local/mysql/data/binlog/binlog.index
server-id=1
port=3306
user=mysql
symbolic-links=0
[mysqld_safe]
log-error=/usr/local/mysql/data/mysqld.err

初始化
/usr/local/mysql/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/data --pid-file=/usr/local/mysql/data/data/mysql.pid

故障二:
版本:mysql5.7
使用rpm包安装的mysql,启动时报错
09a32
解决方式:
初始化mysql配置文件
rm -f /etc/my.conf
/etc/rc.d/init.d/mysqld start

故障三:
mysql版本5.7,有次使用docker来部署mysql

[ERROR] --initialize specified but the data directory has files in it. Abort

删除/var/lib/mysql/* 注意看是不是某个外面的文件映射到/var/lib/mysql里去了导致初始化失败

故障四:
mysql版本5.7,有次使用docker来部署mysql

Please read "Security" section of the manual to find out how to run mysqld as root!

mysql初始化为自动创建一个root用户,我们需要去指定用户来初始化
修改两处:一是在my.cnf文件里添加参数user=mysql;二是进行初始化命令的时候mysqld --user=mysql --initiate

故障四:

Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)

这种一般是mysql服务启动还没有完成