关于Docker官方CentOS镜像无法启动mysqld的总结
很多童鞋反映,在Docker官方CentOS镜像中安装了Mysql server后,无法正常启动。
无法正常启动表现为两种情况:
1> 初始完数据库后,mysqld启动报错
2> systemctl start mysqld或者service mysqld start报错
首先重现一下现场。
第一种情况
一、启动CentOS镜像,安装Mysql Server
注意,Docker官方CentOS镜像latest版本是7.1。CentOS 7 yum源中默认没有Mysql Server的。
关于如何在CentOS 7中安装Mysql Server,可参考这篇博客 CentOS 7中如何安装mysql server
二、初始化数据库
[root@e80a5553b647 ~]# mysql_install_db
三、启动Mysqld服务
[root@e80a5553b647 ~]# mysqld
2015-09-25 03:46:43 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-09-25 03:46:43 0 [Note] mysqld (mysqld 5.6.26) starting as process 775 ...
2015-09-25 03:46:43 775 [ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
2015-09-25 03:46:43 775 [ERROR] Aborting
2015-09-25 03:46:43 775 [Note] Binlog end
2015-09-25 03:46:43 775 [Note] mysqld: Shutdown complete
报以上错误。很多童鞋到这一步就不知所措了,怎么会启动失败呢?但细心的童鞋看到报错信息,就知道失败的原因在于mysqld命令是用roor身份执行的。
四、尝试以mysql身份启动Mysqld服务
[root@e80a5553b647 ~]# mysqld --user=mysql
2015-09-25 02:56:43 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-09-25 02:56:43 0 [Note] mysqld (mysqld 5.6.26) starting as process 167 ...
2015-09-25 02:56:43 167 [Note] Plugin 'FEDERATED' is disabled.
mysqld: Can't find file: './mysql/plugin.frm' (errno: 13 - Permission denied)
2015-09-25 02:56:43 167 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2015-09-25 02:56:43 167 [Note] InnoDB: Using atomics to ref count buffer pool pages
2015-09-25 02:56:43 167 [Note] InnoDB: The InnoDB memory heap is disabled
2015-09-25 02:56:43 167 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-09-25 02:56:43 167 [Note] InnoDB: Memory barrier is not used
2015-09-25 02:56:43 167 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-09-25 02:56:43 167 [Note] InnoDB: Using Linux native AIO
2015-09-25 02:56:43 167 [Note] InnoDB: Using CPU crc32 instructions
2015-09-25 02:56:43 167 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-09-25 02:56:43 167 [Note] InnoDB: Completed initialization of buffer pool
2015-09-25 02:56:43 167 [ERROR] InnoDB: ./ibdata1 can't be opened in read-write mode
2015-09-25 02:56:43 167 [ERROR] InnoDB: The system tablespace must be writable!
2015-09-25 02:56:43 167 [ERROR] Plugin 'InnoDB' init function returned error.
2015-09-25 02:56:43 167 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2015-09-25 02:56:43 167 [ERROR] Unknown/unsupported storage engine: InnoDB
2015-09-25 02:56:43 167 [ERROR] Aborting
。。。。。
还是启动失败。
第二种情况
以systemctl启动,
[root@e80a5553b647 ~]# systemctl start mysqld
Failed to get D-Bus connection: No connection to service manager.
[root@e80a5553b647 ~]# service mysqld start
Starting mysqld (via systemctl): Failed to get D-Bus connection: No connection to service manager.
[FAILED]
报“Failed to get D-Bus connection: No connection to service manager.”错误,在网上找了好久,原因在于该CentOS镜像为精简版,有很多包再制作的过程中没有安装。故导致systemctl命令无法启动。
基于第二种情况,很多童鞋就认为CentOS镜像不完善,导致mysql服务无法启动。
失败原因:
深究下去,第一种方式失败的原因在于第二步初始化数据库的时候是用的ROOT账户运行的。这样,会导致数据库的datadir(即/var/lib/mysql)目录的属主为root。
[root@e80a5553b647 ~]# ll /var/lib/mysql/
total 110600
-rw-rw---- 1 root root 50331648 Sep 25 04:46 ib_logfile0
-rw-rw---- 1 root root 50331648 Sep 25 04:46 ib_logfile1
-rw-rw---- 1 root root 12582912 Sep 25 04:46 ibdata1
drwx------ 2 root root 4096 Sep 25 04:46 mysql
drwx------ 2 root root 4096 Sep 25 04:46 performance_schema
因为mysqld在以ROOT账户执行时会出错,这个与数据库初始化无关,而是数据库基于安全的考虑,不推荐使用ROOT账户启动数据库 !!!
而此时,如果指定mysql用户运行mysqld命令,因为var/lib/mysql目录的属主为root,必然报出“mysqld: Can't find file: './mysql/plugin.frm' (errno: 13 - Permission denied)”错误。
正确的启动方式:
主要有以下两种:
1> 初始化数据库时指定以mysql用户运行,即 mysql_install_db --user=mysql
启动mysql服务,同样有两种方式:
(1) mysqld --user=mysql
(2) mysqld_safe
2> 以 /etc/init.d/mysqld start 方式启动
总结:
1> 如果第一次以mysql_install_db初始化数据库,mysqld --user=mysql启动mysql服务失败后,再次用mysql_install_db --user=mysql初始化数据库,还是会启动失败,其实看看来看看/var/lib/mysql/的属主就知道了,
[root@e80a5553b647 /]# ll /var/lib/mysql/
total 110600
-rw-rw---- 1 root root 12582912 Sep 25 05:57 ibdata1
-rw-rw---- 1 root root 50331648 Sep 25 05:57 ib_logfile0
-rw-rw---- 1 root root 50331648 Sep 25 05:57 ib_logfile1
drwx------ 2 mysql mysql 4096 Sep 25 05:57 mysql
drwx------ 2 root root 4096 Sep 25 05:57 performance_schema
只有mysql目录的属主变为mysql了,其它依旧是root,可通过chown -R mysql:mysql /var/lib/mysql重新设置目录的属性。
2> 启动mysql服务失败的原因还是在于对mysql不熟悉,建议看看mysql服务脚本,即/etc/init.d/mysqld。
3> 关于mysql的启动方式和停止方式(与docker无关)
启动方式主要有以下三种:
(1)使用service启动
service mysqld start 在CentOS7中,相当于systemctl start mysqld
(2)使用脚本启动
/etc/inint.d/mysqld start
(3) 使用safe_mysqld或mysqld --user=mysql启动
关闭方式也有以下三种:
(1)使用service关闭
service mysqld stop 在CentOS7中,相当于systemctl stop mysqld
(2)使用脚本关闭
/etc/inint.d/mysqld stop
(3)mysqladmin shutdown
注意:使用safe_mysqld或mysqld --user=mysql启动的服务,只能通过mysqladmin shutdown关闭,不能通过service或脚本关闭。
mysqladmin shutdown可关闭以上三种服务。脚本可关闭service开启的服务,同样service也可关闭脚本开启的服务。
关于Docker官方CentOS镜像无法启动mysqld的总结的更多相关文章
- Docker的centos镜像内无法使用systemctl命令的解决办法
在Docker官方的centos镜像内无法使用systemctl命令的解决办法, 使用该命令docker报错 Failed to get D-Bus connection: Operation not ...
- 【URLOS开发入门】docker官方系统镜像——Alpine入门教程
我们在进行URLOS应用开发时,经常会用到一些基础系统镜像,如:ubuntu.CentOS.Debian等,我们可以通过docker pull命令直接拉取官方镜像. root@ubuntu:~# do ...
- Docker自制CentOS镜像
系统环境:CentOS 7.3 将yum源切换到阿里源 可以直接写成一个脚本 #!/bin/sh mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos ...
- aws查看官方centos镜像imageid
aws ec2 describe-images --owners aws-marketplace --filters Name=product-code,Values=aw0evgkw8e5c1q41 ...
- 2.docker下centos镜像
1.下载并运行 # 交互模式下载并运行centos容器 $ docker run -it centos:latest /bin/bash 1.1 配置centos的环境别名 $ vi /etc/bas ...
- CentOS7安装Docker,运行Nginx镜像、Centos镜像
摘要 总体思路:yum命令直接安装Docker,下载想要的镜像并启动 1.环境,CentOS7 Minimal 64位,Docker必须要64位的系统 2.通过yum命令直接安装,yum instal ...
- 转:Docker创建centos的LNMP镜像
转自:http://www.vckai.com/p/29 1. 安装docker 这个就不说了,不会的可以看下我之前的文章<Docker介绍及安装>. 1)启动docker # serv ...
- Docker创建centos的LNMP镜像
前段时间重装了系统,今天刚好有时间,就用docker安装一个lnmp开发环境,下面是我的安装笔记. 1. 安装docker 这个就不说了,不会的可以看下我之前的文章<Docker介绍及安装> ...
- 『现学现忘』Docker基础 — 35、实战:自定义CentOS镜像
目录 1.前提说明 2.编写Dockerfile文件 3.构建镜像 4.运行镜像 5.列出镜像的变更历史 1)目标:自定义镜像wokong_centos. 2)所用到的保留字指令: FROM:基础镜像 ...
随机推荐
- About_全在里面
分享·地址:http://www.itxueyuan.org/view/6254.html
- Android :fragment介绍
一.关于Fragmemt 1.Fragment(片段),主要是为了支持更多的动态和灵活的用户界面设计,如平板电脑.Fragment允许组合和交换用户界面组件,而不需要更改视图层次结构.通过把Activ ...
- DirectX游戏编程(一):创建一个Direct3D程序
一.环境 Visual Studio 2012,DirectX SDK (June 2010) 二.准备 1.环境变量(如没有配置请添加) 变量名:DXSDK_DIR 变量值:D:\Software\ ...
- PHP中include()与require()的区别说明
require 的使用方法如 require("MyRequireFile.php"); .这个函数通常放在 PHP 程序的最前面,PHP 程序在执行前,就会先读入 require ...
- Tomcat 配置续
为了便于tomcat升级 不用频繁重新修改相关配置文件 不用重新部署原有项目 新建目录将tomcat安装目录中的conf,log,webapp,work文件夹复制到里面,然后将系统变量里的CATALI ...
- jQuery代码节选(筛选)
筛选...8.not()<p class="p1">1</p><p class="p2">2</p><p ...
- c/c++头文件_string
string, cstring, string.h 一.string头文件 主要包含一些字符串转换的函数 // sto* NARROW CONVERSIONS// sto* WIDE CONVERSI ...
- java 心得
11. 最后的笑声 package javaBookPractice; public class LastLaugh { public static void main(String[] args) ...
- java的英文词频算法
java实现的英文词频算法,通常是采用单词树来实现的.使用java实现词频统计,为了统计词汇出现频率,最简单的做法是再建立一个map,其中,key是单词,value代表次数.将文章从头读到尾,读到一个 ...
- fwrite写入文件不成功bug
文件写入了,只是从头覆盖了!因为在fwrite():前面 文件位置指针是是SEEK_SET,即首位置.在fwrite(fileHeader, 1, 10, file); 前面加上一行fseek(fil ...