免费网站建设方案优化,企业型网站建设费用,天水新闻 今天 头条 最新,wordpress实现知识库目录很多童鞋反映#xff0c;在Docker官方CentOS镜像中安装了Mysql server后#xff0c;无法正常启动。无法正常启动表现为两种情况#xff1a;1 初始完数据库后#xff0c;mysqld启动报错2 systemctl start mysqld或者service mysqld start报错首先重现一下现场。第一…很多童鞋反映在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二、初始化数据库[roote80a5553b647 ~]# mysql_install_db三、启动Mysqld服务[roote80a5553b647 ~]# mysqld2015-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 asroot!2015-09-25 03:46:43 775 [ERROR]Aborting2015-09-25 03:46:43 775 [Note] Binlog end2015-09-25 03:46:43 775 [Note] mysqld: Shutdown complete报以上错误。很多童鞋到这一步就不知所措了怎么会启动失败呢但细心的童鞋看到报错信息就知道失败的原因在于mysqld命令是用roor身份执行的。四、尝试以mysql身份启动Mysqld服务[roote80a5553b647 ~]# mysqld --usermysql2015-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 isdisabled.mysqld: Cant find file:./mysql/plugin.frm(errno: 13 - Permission denied)2015-09-25 02:56:43 167 [ERROR] Cant open the mysql.plugin table. Please run mysql_upgrade to createit.2015-09-25 02:56:43 167 [Note] InnoDB: Using atomics to ref countbuffer pool pages2015-09-25 02:56:43 167 [Note] InnoDB: The InnoDB memory heap isdisabled2015-09-25 02:56:43 167 [Note] InnoDB: Mutexes and rw_locks useGCC atomic builtins2015-09-25 02:56:43 167 [Note] InnoDB: Memory barrier is notused2015-09-25 02:56:43 167 [Note] InnoDB: Compressed tables use zlib 1.2.32015-09-25 02:56:43 167 [Note]InnoDB: Using Linux native AIO2015-09-25 02:56:43 167 [Note]InnoDB: Using CPU crc32 instructions2015-09-25 02:56:43 167 [Note] InnoDB: Initializing buffer pool, size 128.0M2015-09-25 02:56:43 167 [Note] InnoDB: Completed initialization ofbuffer pool2015-09-25 02:56:43 167 [ERROR] InnoDB: ./ibdata1 cant be opened in read-write mode2015-09-25 02:56:43 167 [ERROR] InnoDB: The system tablespace must be writable!2015-09-25 02:56:43 167 [ERROR] PluginInnoDBinit function returned error.2015-09-25 02:56:43 167 [ERROR] PluginInnoDBregistration as a STORAGE ENGINE failed.2015-09-25 02:56:43 167 [ERROR] Unknown/unsupported storage engine: InnoDB2015-09-25 02:56:43 167 [ERROR] Aborting。。。。。还是启动失败。第二种情况以systemctl启动[roote80a5553b647 ~]# systemctl start mysqldFailedto get D-Bus connection: No connection toservice manager.[roote80a5553b647 ~]# service mysqld startStarting mysqld (via systemctl): Failedto get D-Bus connection: No connection toservice manager.[FAILED]报“Failed to get D-Bus connection: No connection to service manager.”错误在网上找了好久原因在于该CentOS镜像为精简版有很多包再制作的过程中没有安装。故导致systemctl命令无法启动。基于第二种情况很多童鞋就认为CentOS镜像不完善导致mysql服务无法启动。失败原因深究下去第一种方式失败的原因在于第二步初始化数据库的时候是用的ROOT账户运行的。这样会导致数据库的datadir(即/var/lib/mysql)目录的属主为root。[roote80a5553b647 ~]# ll /var/lib/mysql/total110600-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 ibdata1drwx------ 2 root root 4096 Sep 25 04:46 mysqldrwx------ 2 root root 4096 Sep 25 04:46 performance_schema因为mysqld在以ROOT账户执行时会出错这个与数据库初始化无关而是数据库基于安全的考虑不推荐使用ROOT账户启动数据库 而此时如果指定mysql用户运行mysqld命令因为var/lib/mysql目录的属主为root必然报出“mysqld: Cant find file: ./mysql/plugin.frm (errno: 13 - Permission denied)”错误。正确的启动方式主要有以下两种1 初始化数据库时指定以mysql用户运行即 mysql_install_db --usermysql启动mysql服务同样有两种方式(1) mysqld --usermysql(2) mysqld_safe2 以 /etc/init.d/mysqld start 方式启动总结1 如果第一次以mysql_install_db初始化数据库mysqld --usermysql启动mysql服务失败后再次用mysql_install_db --usermysql初始化数据库还是会启动失败其实看看来看看/var/lib/mysql/的属主就知道了[roote80a5553b647 /]# ll /var/lib/mysql/total110600-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_logfile1drwx------ 2 mysql mysql 4096 Sep 25 05:57 mysqldrwx------ 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 --usermysql启动关闭方式也有以下三种(1)使用service关闭service mysqld stop 在CentOS7中相当于systemctl stop mysqld(2)使用脚本关闭/etc/inint.d/mysqld stop(3)mysqladmin shutdown注意使用safe_mysqld或mysqld --usermysql启动的服务只能通过mysqladmin shutdown关闭不能通过service或脚本关闭。mysqladmin shutdown可关闭以上三种服务。脚本可关闭service开启的服务同样service也可关闭脚本开启的服务。