mysql 5.6.25启动不起来

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介: <p>mysql 关机启动不起来。</p> <p>又不报错</p> <p>环境:</p> <p><br></p> <p>centos 7 </p> <p>mysql 5.6.25</p> <p><br></p> <p>log-error=/var/log/mysqld.log</p> pid-file=/var/run/mysqld/mysqld.pid<br> [roo

mysql 关机启动不起来。

又不报错

环境:


centos 7 

mysql 5.6.25


log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid
[root@WIN-P11PIHOSG63 ~]# tail -20 /var/log/mysqld.log
2016-03-04 14:02:31 5201 [Note] Shutting down plugin 'INNODB_LOCKS'
2016-03-04 14:02:31 5201 [Note] Shutting down plugin 'INNODB_TRX'
2016-03-04 14:02:31 5201 [Note] Shutting down plugin 'InnoDB'
2016-03-04 14:02:31 5201 [Note] InnoDB: FTS optimize thread exiting.
2016-03-04 14:02:31 5201 [Note] InnoDB: Starting shutdown...
2016-03-04 14:02:33 5201 [Note] InnoDB: Shutdown completed; log sequence number 808362591
2016-03-04 14:02:33 5201 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
2016-03-04 14:02:33 5201 [Note] Shutting down plugin 'ARCHIVE'
2016-03-04 14:02:33 5201 [Note] Shutting down plugin 'BLACKHOLE'
2016-03-04 14:02:33 5201 [Note] Shutting down plugin 'MEMORY'
2016-03-04 14:02:33 5201 [Note] Shutting down plugin 'CSV'
2016-03-04 14:02:33 5201 [Note] Shutting down plugin 'MyISAM'
2016-03-04 14:02:33 5201 [Note] Shutting down plugin 'MRG_MYISAM'
2016-03-04 14:02:33 5201 [Note] Shutting down plugin 'sha256_password'
2016-03-04 14:02:33 5201 [Note] Shutting down plugin 'mysql_old_password'
2016-03-04 14:02:33 5201 [Note] Shutting down plugin 'mysql_native_password'
2016-03-04 14:02:33 5201 [Note] Shutting down plugin 'binlog'
2016-03-04 14:02:33 5201 [Note] /usr/sbin/mysqld: Shutdown complete


160304 14:02:34 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

[root@WIN-P11PIHOSG63 ~]# ls -ld /var/run/mysqld/


my.cnf

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M


basedir=/usr
datadir=/var/lib/mysql
tmpdir=/tmp 
socket=/var/lib/mysql/mysql.sock
#slave_load_tmpdir=/tmp
#symbolic-links=0
#skip-name-resolve
##skip-symbolic-links
#max_connect_errors = 10000
#max_connections = 500
#wait-timeout = 30
#new add dba
#binlog-format=ROW
#log-bin=master-bin
#log-slave-updates=true
#gtid-mode=on 
#enforce-gtid-consistency=true
#master-info-repository=TABLE
#relay-log-info-repository=TABLE
#sync-master-info=1
#slave-parallel-workers=2
#binlog-checksum=CRC32
#master-verify-checksum=1
#slave-sql-verify-checksum=1
#binlog-rows-query-log_events=1
server-id=1
#report-port=3306
port=3306
#report-host=WIN-P11PIHOSG63.lan
#rpl_semi_sync_master_enabled=ON


# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

解决:
[mysqld_safe]
log-error=/var/log/mysqld.log
#pid-file=/var/run/mysqld/mysqld.pid  #注释掉这行


service mysqld start

或者

/bin/systemctl start  mysqld.service



赠送思路:


今天,启动MySQL服务器失败,如下所示:

[root@spark01 ~]# /etc/init.d/mysqld start
Starting mysqld (via systemctl):  Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
                                                           [FAILED]

根据提示,分别使用systemctl status mysqld.service和journalctl -xe查看服务启动失败的原因

[root@spark01 ~]# systemctl status mysqld.service

复制代码
?.mysqld.service - SYSV: MySQL database server.
   Loaded: loaded (/etc/rc.d/init.d/mysqld)
   Active: failed (Result: exit-code) since Wed 2016-01-20 18:26:57 CST; 40s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 2979 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=1/FAILURE)

Jan 20 18:26:56 spark01 systemd[1]: Starting SYSV: MySQL database server....
Jan 20 18:26:57 spark01 mysqld[2979]: MySQL Daemon failed to start.
Jan 20 18:26:57 spark01 mysqld[2979]: Starting mysqld:  [FAILED]
Jan 20 18:26:57 spark01 systemd[1]: mysqld.service: control process exited, code=exited status=1
Jan 20 18:26:57 spark01 systemd[1]: Failed to start SYSV: MySQL database server..
Jan 20 18:26:57 spark01 systemd[1]: Unit mysqld.service entered failed state.
Jan 20 18:26:57 spark01 systemd[1]: mysqld.service failed.
复制代码

[root@spark01 ~]# journalctl -xe

复制代码
-- 
-- Unit session-2.scope has begun starting up.
Jan 20 18:26:48 spark01 sshd[2916]: pam_unix(sshd:session): session opened for user spark by (uid=0)
Jan 20 18:26:52 spark01 su[2944]: (to root) spark on pts/1
Jan 20 18:26:52 spark01 su[2944]: pam_unix(su-l:session): session opened for user root by spark(uid=1000)
Jan 20 18:26:56 spark01 polkitd[909]: Registered Authentication Agent for unix-process:2974:117137 (system bus name :1.25
Jan 20 18:26:56 spark01 systemd[1]: Starting SYSV: MySQL database server....
-- Subject: Unit mysqld.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mysqld.service has begun starting up.
Jan 20 18:26:57 spark01 mysqld[2979]: MySQL Daemon failed to start.
Jan 20 18:26:57 spark01 mysqld[2979]: Starting mysqld:  [FAILED]
Jan 20 18:26:57 spark01 systemd[1]: mysqld.service: control process exited, code=exited status=1
Jan 20 18:26:57 spark01 systemd[1]: Failed to start SYSV: MySQL database server..
-- Subject: Unit mysqld.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mysqld.service has failed.
-- 
-- The result is failed.
Jan 20 18:26:57 spark01 systemd[1]: Unit mysqld.service entered failed state.
Jan 20 18:26:57 spark01 systemd[1]: mysqld.service failed.
Jan 20 18:26:57 spark01 polkitd[909]: Unregistered Authentication Agent for unix-process:2974:117137 (system bus name :1.
复制代码

但,可惜的时,这些信息并不能提供服务启动失败的真正原因。

这时候,不妨打开MySQL的告警日志,毕竟,只要MySQL服务启动,告警日志都会有输出信息的,果然

2016-01-20T10:00:19.935771Z 0 [ERROR] /usr/sbin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2 - No such file or directory)
2016-01-20T10:00:19.935795Z 0 [ERROR] Can't start server: can't create PID file: No such file or directory
160120 18:00:20 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

MySQL服务在启动的时候,不能创建pid文件。

在终端看一下该目录是否存在,果然,不存在。

于是,创建了/var/run/mysqld/目录,重启MySQL服务

[root@spark01 ~]# mkdir -p /var/run/mysqld/

[root@spark01 ~]# /etc/init.d/mysqld start

Starting mysqld (via systemctl):  Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
                                                           [FAILED]

依旧报错,重新查看告警日志,有以下输出

2016-01-20T10:28:37.183387Z 0 [ERROR] /usr/sbin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 13 - Permission denied)
2016-01-20T10:28:37.183431Z 0 [ERROR] Can't start server: can't create PID file: Permission denied
160120 18:28:37 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
160120 18:32:06 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

原来,/var/run/mysqld/的属主和属组还是root,mysql并不能在其中创建文件,后修改该目录的属主和属组,启动OK。

[root@spark01 ~]# ls -ld /var/run/mysqld/
drwxr-xr-x 2 root root 40 Jan 20 18:28 /var/run/mysqld/
[root@spark01 ~]# chown mysql.mysql /var/run/mysqld/
[root@spark01 ~]# /etc/init.d/mysqld start
Starting mysqld (via systemctl):                           [  OK  ]

 

总结:

以前在玩Kubernetes的时候,常遇到启动失败的情况,根据systemctl的提示,通过systemctl status mysqld.service和journalctl -xe命令查看服务启动失败的原因往往并不如人意,反而给了一种错误的暗示,以为这个跟系统有关。其实,通过查看服务的日志,往往更能清晰的知道服务启动失败的原因。

 

参考:

http://www.cnblogs.com/ivictor/p/5146247.html





相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
关系型数据库 MySQL Shell
Docker 上安装、启动 MySQL
Docker 上安装、启动 MySQL
1202 0
Docker 上安装、启动 MySQL
|
关系型数据库 MySQL C++
MySQL安装出现应用程序无法正常启动(0xc000007b)
Windows MySQL安装出现应用程序无法正常启动(0xc000007b)
2491 0
MySQL安装出现应用程序无法正常启动(0xc000007b)
|
关系型数据库 MySQL Windows
MySQL启动时显示:发生系统错误 5。拒绝访问解决办法
MySQL启动时显示:发生系统错误 5。拒绝访问解决办法
MySQL启动时显示:发生系统错误 5。拒绝访问解决办法
|
安全 关系型数据库 MySQL
面向WEB开发的Docker(四):启动MySQL数据库
在本文中,将来学习如何使用Docker CLI和Docker compose启动MySQL容器。
314 0
面向WEB开发的Docker(四):启动MySQL数据库
|
关系型数据库 MySQL 程序员
在 Windows 命令提示符下启动 MySQL:net start mysql 发生系统错误 5。 拒绝访问。解决方式小结
在 Windows 命令提示符下启动 MySQL:net start mysql 发生系统错误 5。 拒绝访问。解决方式小结
902 1
在 Windows 命令提示符下启动 MySQL:net start mysql 发生系统错误 5。 拒绝访问。解决方式小结
|
关系型数据库 MySQL Windows
安装和启动mysql in Windows 8
安装和启动mysql in Windows 8
163 0
安装和启动mysql in Windows 8
|
关系型数据库 MySQL 数据库
MySQL无法启动的问题->MySQL 服务正在启动 . MySQL 服务无法启动。服务没有报告任何错误。 请键入 NET HELPMSG 3534 以获得更多的帮助
注意以上的操作会清除数据库内容及已经创建的数据库用户,会生成一个新的用户root,此用户没有密码🐱‍🏍
412 0
MySQL无法启动的问题->MySQL 服务正在启动 . MySQL 服务无法启动。服务没有报告任何错误。 请键入 NET HELPMSG 3534 以获得更多的帮助
|
canal SQL 关系型数据库
mysql 悬案 之 为什么用 docker 启动的 mysql 配置文件不生效
mysql 悬案 之 为什么用 docker 启动的 mysql 配置文件不生效
1740 0
|
关系型数据库 MySQL
|
关系型数据库 MySQL Java
【问题解决】mysql数据库启动时报服务启动后停止。某些服务在未由其他服务或程序使用时将自动停止
【问题解决】mysql数据库启动时报服务启动后停止。某些服务在未由其他服务或程序使用时将自动停止
【问题解决】mysql数据库启动时报服务启动后停止。某些服务在未由其他服务或程序使用时将自动停止