转自: http://support.moonpoint.com/software/database/mysql/not-running-centos7.php

下面简单翻译一下。 详细内容可以阅读英文原文。

笔者的情况是这样的。购买的linode VPS 默认使用wordpress的 centos7 模板为环境一键安装的。 安装完成后,导入WP数据库上传wordpress主题,配置环境设置文件夹权限, 域名解析过去,完毕后一切正常。但是第二天,忽然就无法访问数据库了。 使用控制台连进去之后发现mysql服务死掉了。 重启命令无效,重启系统无效。

service mysqld start

始终提示如下:

Failed to issue method call: Unit mysqld.service failed to load: No such file or directory.

死活都提示找不到。

无奈,网上搜索半天总算找到一个可以用的。 其实是默认的这个环境一起安装了一个叫MariaDB的东西(可以把它理解为mysql的安全向导),帮助提高mysql的安全性。

原文的思路如下,先查看mysql版本,发现是mysql是有的,但是为何提示不存在呢,那就一步步排查原因。

后面就找到 etc/my.cnf 这个文件打开查看引用的各个路径,也都一一找到了。 那这到底是为啥呢,这老外也是百思不得解,然后他也进行了搜索,搜到一篇stackoverflow的内容,就是安装MariaDB之后,就找不到mysqld了。于是乎一楼的答案就给出了:

安装MariaDB之后必须先启动MariaDB才能启动mysqld,其实就是运行一下MariaDB向导,它是个一次性的东东,就是帮助你提高mysql安全性的,详细看这里:http://www.jb51.net/article/47727.htm

总结一下就是运行下面三句就搞定啦:

systemctl start mariadb.service
systemctl enable mariadb.service
mysql_secure_installation

MySQL service not running on CentOS 7 system

I had installed the MariaDB, a fork of the MySQL relational database management system (RDBMS) on a CentOS 7 system when I set up the system. When I checked the version of the software with the mysql --version command, I saw the following:

# mysql --version
mysql Ver 15.1 Distrib 5.5.37-MariaDB, for Linux (x86_64) using readline 5.1

But, when I ran the mysql command on the system, I received the error message shown below:

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

I checked to see if the mysqld service was running and found it was not.

# systemctl status mysqld.service
mysqld.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)

When I tried to start the service, it wouldn't start.

# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
Failed to issue method call: Unit mysqld.service failed to load: No such file or directory.
# systemctl start mysqld.service
Failed to issue method call: Unit mysqld.service failed to load: No such file or directory.

I checked the contents of the /etc/my.cnf file and saw the following:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd [mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid #
# include all files from the config directory
#
!includedir /etc/my.cnf.d

I checked for the existence of files and directories listed in that file. I saw the following results for the locations for datadirsocketlog-error, and pid-file:

# ls -ld /var/lib/mysql
drwxr-xr-x. 19 mysql mysql 4096 Oct 14 23:46 /var/lib/mysql
[root@localhost install]# ls -l /var/lib/mysql/mysql.sock
srwxrwxrwx. 1 mysql mysql 0 Sep 29 15:05 /var/lib/mysql/mysql.sock
# ls -l /var/log/mariadb/mariadb.log
-rw-r-----. 1 mysql mysql 0 Oct 5 20:49 /var/log/mariadb/mariadb.log
# ls -l /var/run/mariadb/mariadb.pid
ls: cannot access /var/run/mariadb/mariadb.pid: No such file or directory

I didn't see any mariadb.pid file, but I wouldn't expect it to be created until the mysqld service successfully started.

When I checked the files in the includedir directory, I saw the following:

# ls -l /etc/my.cnf.d
total 12
-rw-r--r--. 1 root root 295 Apr 15 2014 client.cnf
-rw-r--r--. 1 root root 232 Apr 15 2014 mysql-clients.cnf
-rw-r--r--. 1 root root 744 Apr 15 2014 server.cnf

So I didn't know why I was getting the "Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'" message when I issued the command mysql nor why my attempt to start the mySQL service failed with a "No such file or directory" message. Searching online, I found a posting by danneth at No mysqld or mysql.server after mariadb-server install to use systemctl start mariadb.service. When I used that command, I didn't see any error messages. I tried thesystemctl startus mysqld service after issuing the command, but still saw a error message for it. But, when I then issued the mysql command I received an "access denied" message this time, which seemed reasonable, since I hadn't provided the password for the root account when I issued the command..

# systemctl start mariadb.service
# systemctl status mysqld service
mysqld.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead) service.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead) # mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

When I was using CentOS 5, I had MySQL rather than MariaDB and I didn't know I needed to start the MariaDB RDBMS service on the CentOS 7 system using a command referencing mariadb rather mysqld. I assumed I could reference mysqld to start the service.

The history behind the creation of MariaDB can be found in the history section of the Wikipedia article on MySQL. MariaDB was created by one of the cofounders of MySQL, Michael Widenius, after Oracle Corporation obtained rights to the MySQL software from Sun Microsystems.

To have the MariaDB service start automatically each time the system boots, issue the command systemctl enable mariadb.service. After you have started the service, also issue the command mysql_secure_installation.

# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here. Enter current password for root (enter for none):
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Enter current password for root (enter for none):
OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation. You already have a root password set, so you can safely answer 'n'. Change the root password? [Y/n] n
... skipping. By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment. Remove anonymous users? [Y/n] y
... Success! Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] Y
... Success! By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment. Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success! Reloading the privilege tables will ensure that all changes made so far
will take effect immediately. Reload privilege tables now? [Y/n] Y
ERROR 1146 (42S02) at line 1: Table 'mysql.servers' doesn't exist
... Failed! Cleaning up... All done! If you've completed all of the above steps, your MariaDB
installation should now be secure. Thanks for using MariaDB!

I had it remove the anonymous account, since leaving it would be a security vulnerability. I also chose to disallow remote root login to MariaDB and the test database for the same reason.

I had copied the contents of the /var/lib/mysql directory from the hard drive of the prior CentOS 5 system to the new CentOS 7 system to have all of the databases from the old system available on the new system, so that appeared to be the reason that the mysql_secure_installation, which can be found in /usr/bin, did not accept my just hitting Enter for the password initially. When I entered the root password for MySQL on the old system, it was accepted. And I was able finally get a prompt where I could enter SQL commands using that password with mysql -u root -p .

# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 5.5.37-MariaDB MariaDB Server Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>

So the 3 steps to enable and run MariaDB are as follows, assuming it was previously installed during the initial setup for the system or with yum install mariadb mariadb-server:

systemctl start mariadb.service
systemctl enable mariadb.service
mysql_secure_installation

linux mysql无故无法启动了,centos 7的更多相关文章

  1. Linux MySQL 常见无法启动或启动异常的解决方案

    Linux MySQL 常见无法启动或启动异常的解决方案 在 Linux 上自建 MySQL 服务器,经常遇到各种无法启动或启动后异常的问题,本文列举一些常见问题的解决办法. 注意:以下错误日志提示, ...

  2. Linux配置redis开机启动(CentOS 7)

    https://blog.csdn.net/qq_31803503/article/details/79246205 本次配置linux版本是CentOS 7 首先将  redis-3.2.3/uti ...

  3. Linux MySql状态、启动、停止、重启命令

    1.查看mysql状态 [1]ps -ef|grep mysqld 看看是否有mysqld_safe 和mysqld进程 [root@localhost ~]# ps -ef|grep mysqld ...

  4. Linux CentOS下如何确认MySQL服务已经启动

    Linux CentOS一般做为服务器使用,因此,MySQL服务应该随开机自动启动的.正常情况下,查看开机自动启动的服务使用chkconfig命令,如下: #chkconfig --list 实际使用 ...

  5. Linux Centos7下如何确认MySQL服务已经启动

    Linux CentOS一般做为服务器使用,因此,MySQL服务应该随开机自动启动的.正常情况下,查看开机自动启动的服务使用chkconfig命令,如下: #chkconfig --list 实际使用 ...

  6. 制作U盘启动安装CentOS Linux系统

    制作U盘启动安装CentOS Linux系统 (特为老男孩教育&&51CTO学院在线三期同学而发) 方法一:使用UltraISO,将u盘做成启动盘 文件-->打开-->选择 ...

  7. CentOS: Make Command not Found and linux xinetd 服务不能启动

    在centos 安装编译器 yum -y install gcc automake autoconf libtool make linux xinetd 服务不能启动: [root@capaa xin ...

  8. Linux下安装mysql(2) 及常见问题解决(CentOS)

    上一篇讲了基本的安装,这篇姑且算作进阶吧 链接Linux下安装mysql(1) 1.准备好mysql的rpm安装包 2.解压并进入usr/local/mysql 3.先执行useradd mysql( ...

  9. Linux中(Ubuntu18.04.x/CentOS)mysql8.0.x安装/配置/部署/启动

    The MySQL Connectors and APIs are the drivers and libraries that you use to connect applications in ...

随机推荐

  1. 在asp.net web api 2 使用 Serilog 记录日志

    Serilog是.net里面非常不错的记录日志的库,另外一个我认为比较好的Log库是NLog. 在我个人的asp.net web api 2 基础框架(Github地址)里,我原来使用的是NLog,但 ...

  2. Rectangles hdu2461容斥定理

    Rectangles Time Limit: 5000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  3. Beautiful Dream hdu3418 (直接做或二分)

    Beautiful Dream Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  4. Linux查找和筛选工具

    本文为原创文章,转载请标明出处 目录 文件名通配符 单字符匹配元字符 ? 多字符匹配元字符 * 字符范围匹配符 [] 排除范围匹配符 [!] 命令中的正则表达式 单字符匹配符 . 单字符或字符串重复匹 ...

  5. ASP.NET没有魔法——ASP.NET MVC 与数据库之Entity Framework Migrations

    在开发数据库应用程序的时候,经常会遇到某些表需要添加字段或者修改类型.新增表等需求,而对于EF Code First来说关注的只有实体类,当需求变更时只需要添加新的实体类或者在实体类中添加.删除.修改 ...

  6. zookeeper curator选主(Leader)

    在分布式系统设计中,选主是一个常见的场景.选主是一个这样的过程,通过选主,主节点被选择出来控制其他节点或者是分配任务. 选主算法要满足的几个特征: 1)各个节点均衡的获得成为主节点的权利,一旦主节点被 ...

  7. 使用beanstalkd实现定制化持续集成过程中pipeline

    持续集成是一种项目管理和流程模型,依赖于团队中各个角色的配合.各个角色的意识和配合不是一朝一夕能练就的,我们的工作只是提供一种方案和能力,这就是持续集成能力的服务化.而在做持续集成能力服务化的过程中, ...

  8. 平板不能设置代理的情况下利用随身wifi进行http代理访问

    需求来源:平板或手机是个封闭系统无法给wifi设置代理,需要利用filllder进行抓包,内容篡改等实验 拥有硬件资源:PC机器 + 小米随身wifi 方案1: NtBind Dns + Nginx ...

  9. elasticsearch高级组合查询ava

    /**     * 高级检索(组合条件检索)must相当于sql and操作     * @param modelType 0为模糊查询,1为精确查询     * @param index 索引   ...

  10. JAVAEE企业级应用开发浅谈第一辑

    不积跬步无以至千里,不积小流无以成江海 Step1.情景概要 作为一个JAVA WEB 开发人员,在开发web 项目时项目大家都有自己的一些新的体会,对于web 开发出现的一些比较经典的名词大家都会有 ...