linux下自己创建/etc/my.cnf文件导致启动mysql时报错:

时间:2022-05-02 17:30:15

Starting MySQL........ ERROR! The server quit without updating PID file (/var/lib/mysql/mini1.pid).


===

过程:rpm方式安装mysql5.6没有配置文件/etc/my.cnf

于是自己拷了一份其他linux上的配置文件(已配置好双主,其中修改了默认编码为utf8,部分配置如下:)


[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

collation_server = utf8_general_ci                      # collation 比对方法

character_set_server = utf8

rpl_semi_sync_slave_enabled=1


==

登陆mysql,show variables likecharacter%; 发现server端编码仍为latin1


| character_set_database   | latin1                     |

| character_set_server     | latin1 


==

检查发现新建配置文件后未重启mysql服务,于是重启。service mysql restart 报错:

Shutting down MySQL.. SUCCESS!

Starting MySQL........ ERROR! The server quit without updating PID file (/var/lib/mysql/mini1.pid).


==

查看日志:


[root@mini1 scripts]# tail -20 /var/log/mysqld.log

2017-08-06 09:25:56 1649 [Note] InnoDB: Starting shutdown...

2017-08-06 09:25:58 1649 [Note] InnoDB: Shutdown completed; log sequence number 1630108

2017-08-06 09:25:58 1649 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'

2017-08-06 09:25:58 1649 [Note] Shutting down plugin 'BLACKHOLE'

2017-08-06 09:25:58 1649 [Note] Shutting down plugin 'ARCHIVE'

2017-08-06 09:25:58 1649 [Note] Shutting down plugin 'CSV'

2017-08-06 09:25:58 1649 [Note] Shutting down plugin 'MEMORY'

2017-08-06 09:25:58 1649 [Note] Shutting down plugin 'MRG_MYISAM'

2017-08-06 09:25:58 1649 [Note] Shutting down plugin 'MyISAM'

2017-08-06 09:25:58 1649 [Note] Shutting down plugin 'sha256_password'

2017-08-06 09:25:58 1649 [Note] Shutting down plugin 'mysql_old_password'

2017-08-06 09:25:58 1649 [Note] Shutting down plugin 'mysql_native_password'

2017-08-06 09:25:58 1649 [Note] Shutting down plugin 'binlog'

2017-08-06 09:25:58 1649 [Note] /usr/sbin/mysqld: Shutdown complete

 

170806 09:25:58 mysqld_safe mysqld from pid file /var/lib/mysql/mini1.pid ended


==

杀死进程,重启服务,仍然报错。


[root@mini1 scripts]# pkill mini1

[root@mini1 scripts]# service mysql status

 ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql) exists

[root@mini1 scripts]# rm -rf /var/lock/subsys/mysql

[root@mini1 scripts]# service mysql start

Starting MySQL........ ERROR! The server quit without updating PID file (/var/lib/mysql/mini1.pid).


==

最后没办法-->>>度娘

1.检查/var/lib下的mysql文件夹所属用户及组皆为mysql

2.ps -ef|grep mysql杀死进程。

3.如果是二次安装,删除数据库目录/data下的mysql-bin.index。

4.[mysqld]下指定datadir=/var/lib/mysql

5.检查my.cnf文件中如果有skip-federated字段将其注释掉

6.配置的错误日志目录是否存在,授权为mysql所有者权限

7.将/etc/selinux/config中的SELINUX=enforcing改为SELINUX=disabled


==

上述依次检查修改完毕,错误依旧。

继续百度,参考文章:http://blog.csdn.net/apple9005/article/details/72420402  

[root@mini1 scripts]# rpm -qa | grep mariadb# MariaDB数据库管理系统是MySQL的一个分支。如果有,全部卸载。我这里没有。

[root@mini1 scripts]# cd /var/lib/mysql

[root@mini1 mysql]# less mini1.err

[root@mini1 mysql]# yum -y install autoconf

[root@mini1 mysql]# /usr/bin/mysql_install_db -user=mysql


报错:2017-08-06 09:46:13 2890 [ERROR] /usr/sbin/mysqld: unknown variable 'rpl_semi_sync_slave_enabled=1'
2017-08-06 09:46:13 2890 [ERROR] Aborting
删除my.cnf文件中rpl_semi_sync_slave_enabled=1后,继续执行/usr/bin/mysql_install_db -user=mysql
显示一堆刚安装mysql时修改密码之类的提示信息,
……
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h mini1 password 'new-password'
……

===========================>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

到此,The server quit without updating PID file问题成功解决。

但此时启动mysql,报了另外一个错:

[root@mini1 mysql]# mysql -uroot -proot

Warning: Using a password on the command line interface can be insecure.

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

直接删除/var/lib/mysql/mysql.sock无效。意识到应该是密码错误的问题,以为是重新配置了mysql导致密码需要重新配置,于是使用刚刚提示的mysqladmin修改密码,然而也不行。

[root@mini1 mysql]# /usr/bin/mysqladmin -u root password 'root'

/usr/bin/mysqladmin: connect to server at 'localhost' failed

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

Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!


查看之前收藏过的文章:http://www.360doc.com/content/17/0726/03/44201090_674155868.shtml 


检查发现由于mysql服务未启动导致。。。

[root@mini1 mysql]# service mysql status

 ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql) exists

[root@mini1 mysql]# rm -rf /var/lock/subsys/mysql

[root@mini1 mysql]# service mysql start

Starting MySQL........ SUCCESS!

[root@mini1 mysql]# mysql -uroot -proot

成功登陆mysql,查看编码字符集设置,也全为utf-8!说明已读取了自己配置的/etc/my.cnf文件, 问题解决!