service mysqld start

始终提示如下:

  1. Failed to issue method call: Unit mysqld.service failed to load: No such file or directory.
  2.  
  3. systemctl start/stop mysqld.service
    systemctl start/stop mysql.service

死活都提示找不到。

使用 kill -9 pid 杀掉进程后,只是换了一个pid 又启动了3306端口,

【你是不是用mysqld_safe起的mysql?这是个守护进程,用它起数据库的话,直接kill它会检测到数据库非正常关闭,会自动尝试起数据库。你可以选择先kill掉mysqld_safe的进程然后再kill mysql;或者使用这个命令:kill -9 `ps -ef | grep 'mysqld' | grep -v grep|awk '{print $2}'`】

无奈,网上搜索半天总算找到一个可以用的。 其实是默认的这个环境一起安装了一个叫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_secure_installation。运行mysql_secure_installation会执行几个设置:
  a)为root用户设置密码
  b)删除匿名账号
  c)取消root用户远程登录
  d)删除test库和对test库的访问权限
  e)刷新授权表使修改生效

通过这几项的设置能够提高mysql库的安全。建议生产环境中mysql安装这完成后一定要运行一次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:

  1. # mysql --version
  2. 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:

  1. # mysql
  2. 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.

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

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

  1. # service mysqld start
  2. Redirecting to /bin/systemctl start mysqld.service
  3. Failed to issue method call: Unit mysqld.service failed to load: No such file or directory.
  4. # systemctl start mysqld.service
  5. 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:

  1. [mysqld]
  2. datadir=/var/lib/mysql
  3. socket=/var/lib/mysql/mysql.sock
  4. # Disabling symbolic-links is recommended to prevent assorted security risks
  5. symbolic-links=0
  6. # Settings user and group are ignored when systemd is used.
  7. # If you need to run mysqld under a different user or group,
  8. # customize your systemd unit file for mariadb according to the
  9. # instructions in http://fedoraproject.org/wiki/Systemd
  10.  
  11. [mysqld_safe]
  12. log-error=/var/log/mariadb/mariadb.log
  13. pid-file=/var/run/mariadb/mariadb.pid
  14.  
  15. #
  16. # include all files from the config directory
  17. #
  18. !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:

  1. # ls -ld /var/lib/mysql
  2. drwxr-xr-x. 19 mysql mysql 4096 Oct 14 23:46 /var/lib/mysql
  3. [root@localhost install]# ls -l /var/lib/mysql/mysql.sock
  4. srwxrwxrwx. 1 mysql mysql 0 Sep 29 15:05 /var/lib/mysql/mysql.sock
  5. # ls -l /var/log/mariadb/mariadb.log
  6. -rw-r-----. 1 mysql mysql 0 Oct 5 20:49 /var/log/mariadb/mariadb.log
  7. # ls -l /var/run/mariadb/mariadb.pid
  8. 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:

  1. # ls -l /etc/my.cnf.d
  2. total 12
  3. -rw-r--r--. 1 root root 295 Apr 15 2014 client.cnf
  4. -rw-r--r--. 1 root root 232 Apr 15 2014 mysql-clients.cnf
  5. -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..

  1. # systemctl start mariadb.service
  2. # systemctl status mysqld service
  3. mysqld.service
  4. Loaded: not-found (Reason: No such file or directory)
  5. Active: inactive (dead)
  6.  
  7. service.service
  8. Loaded: not-found (Reason: No such file or directory)
  9. Active: inactive (dead)
  10.  
  11. # mysql
  12. 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.

  1. # mysql_secure_installation
  2. /usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
  3.  
  4. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
  5. SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
  6.  
  7. In order to log into MariaDB to secure it, we'll need the current
  8. password for the root user. If you've just installed MariaDB, and
  9. you haven't set the root password yet, the password will be blank,
  10. so you should just press enter here.
  11.  
  12. Enter current password for root (enter for none):
  13. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
  14. Enter current password for root (enter for none):
  15. OK, successfully used password, moving on...
  16.  
  17. Setting the root password ensures that nobody can log into the MariaDB
  18. root user without the proper authorisation.
  19.  
  20. You already have a root password set, so you can safely answer 'n'.
  21.  
  22. Change the root password? [Y/n] n
  23. ... skipping.
  24.  
  25. By default, a MariaDB installation has an anonymous user, allowing anyone
  26. to log into MariaDB without having to have a user account created for
  27. them. This is intended only for testing, and to make the installation
  28. go a bit smoother. You should remove them before moving into a
  29. production environment.
  30.  
  31. Remove anonymous users? [Y/n] y
  32. ... Success!
  33.  
  34. Normally, root should only be allowed to connect from 'localhost'. This
  35. ensures that someone cannot guess at the root password from the network.
  36.  
  37. Disallow root login remotely? [Y/n] Y
  38. ... Success!
  39.  
  40. By default, MariaDB comes with a database named 'test' that anyone can
  41. access. This is also intended only for testing, and should be removed
  42. before moving into a production environment.
  43.  
  44. Remove test database and access to it? [Y/n] Y
  45. - Dropping test database...
  46. ... Success!
  47. - Removing privileges on test database...
  48. ... Success!
  49.  
  50. Reloading the privilege tables will ensure that all changes made so far
  51. will take effect immediately.
  52.  
  53. Reload privilege tables now? [Y/n] Y
  54. ERROR 1146 (42S02) at line 1: Table 'mysql.servers' doesn't exist
  55. ... Failed!
  56.  
  57. Cleaning up...
  58.  
  59. All done! If you've completed all of the above steps, your MariaDB
  60. installation should now be secure.
  61.  
  62. 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 .

  1. # mysql -u root -p
  2. Enter password:
  3. Welcome to the MariaDB monitor. Commands end with ; or \g.
  4. Your MariaDB connection id is 11
  5. Server version: 5.5.37-MariaDB MariaDB Server
  6. Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.
  7. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  8.  
  9. 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

Centos7以上的版本 mysql 无法启动,无法停止问题的更多相关文章

  1. MySQL 安装和启动服务,“本地计算机 上的 MySQL 服务启动后停止。某些服务在未由其他服务或程序使用时将自动停止。”

    MySQL 安装和启动服务,以及遇到的问题 MySQL版本: mysql-5.7.13-winx64.zip (免安装,解压放到程序文件夹即可,比如 C:\Program Files\mysql-5. ...

  2. 本地计算机上的MySQL服务启动后停止。某些服务在未由其他服务或程序使用时将自动

    重新安装MySQL数据库,由于安装的时候马虎,一路next(事实上,某些地方需要严格的配置,我忘记注意了),导致现在出了很多麻烦. 错误信息: 本地计算机上的MySQL服务启动后停止.某些服务在未由其 ...

  3. mysql5.7 本地计算机上的mysql 服务启动后停止 的问题解决

    mysql5.7 本地计算机上的mysql 服务启动后停止. 问题: 在cmd 下mysql服务mysql服务无法启动任何错误法启动 服务没有报告任何错误     在服务里面启动是   早上来了发现项 ...

  4. mysql57重新安装后无法再次启动mysql57服务“本地计算机上的MySQL服务启动后停止。某些服务在未由其他服务或程序使用时将自动。”--解决方法

    本地计算机上的MySQL服务启动后停止.某些服务在未由其他服务或程序使用时将自动. (win10,mysql5.7+) 解决方法: 第一步:查看MySQL57安装路径 只要在programData路径 ...

  5. CentOS7用yum安装MySQL与启动

    首先CentOS7 已经不支持mysql,因为收费了你懂得,所以内部集成了mariadb,而安装mysql的话会和mariadb的文件冲突,所以需要先卸载掉mariadb,以下为卸载mariadb,安 ...

  6. Centos7下Jewel版本radosgw服务启动

    前言 本篇介绍了centos7下jewel版本的radosgw配置,这里的配置是指将服务能够正常起来,不涉及到S3的配置,以及其他的更多的配置,radosgw后面的gw就是gateway的意思,也就是 ...

  7. mysql服务启动、停止、重启

    如何启动/停止/重启MySQL 一.启动方式 1.使用 service 启动:service mysqld start 2.使用 mysqld 脚本启动:/etc/inint.d/mysqld sta ...

  8. 关于在安装MySQL时报错"本地计算机上的mysql服务启动后停止,某些服务在未由其他服务或程序使用时将自动停止"的解决方法

    首先将你下载的MySQL安装或者解压(对应安装版和解压版),下载地址http://dev.mysql.com/downloads/mysql/ 然后复制你安装目录中的my-default.ini,更改 ...

  9. MySQL的启动与停止

    如果MySQL数据库是自己安装的,可以用如下方法分别启动和停止MySQL. 1. MySQL服务器的启动 $mysql_dir/bin/mysqld_safe &         (其中&am ...

随机推荐

  1. [ADC]TI am4378 ADC采样设置问题(am335x类似)

    这段时间在调试AM4378的ADC问题,发现采样到的数据和真实输入波形有所出入,比如输入是1ms的周期,50%占空比的信号,但是采样的数据描点总是偏差较大,数据如下 iio device number ...

  2. 数据库并发事务控制四:postgresql数据库的锁机制二:表锁 <转>

    在博文<数据库并发事务控制四:postgresql数据库的锁机制 > http://blog.csdn.net/beiigang/article/details/43302947 中后面提 ...

  3. MATLAB实现多元线性回归预测

    一.简单的多元线性回归: data.txt ,230.1,37.8,69.2,22.1 ,44.5,39.3,45.1,10.4 ,17.2,45.9,69.3,9.3 ,151.5,41.3,58. ...

  4. CAS (10) —— JBoss EAP 6.4下部署CAS时出现错误exception.message=Error decoding flow execution的解决办法

    CAS (10) -- JBoss EAP 6.4下部署CAS时出现错误exception.message=Error decoding flow execution的解决办法 jboss版本: jb ...

  5. Spring Cloud Config 配置高可用集群

    详细参考:<Sprin Cloud 与 Docker 微服务架构实战>p163-9.10节 spring cloud config 与 eureka 配合使用 我就不写了,请参见本书章节.

  6. Controllerizing the ScrollViewer Thumbnail

    In the last post we created a ScrollViewer Thumbnail feature using a just a bit of Xaml and databind ...

  7. 【转】Android下使用配置文件(Preferences)

    http://www.aslibra.com/blog/post/android_SharedPreferences.php android下可以方便的使用key-value的配置文件: // S.P ...

  8. 关于Unity中场景的导入与导出(专题九)

    Unity场景 场景虽然是由场景美术做好的,但是我们经常需要自己去导导出以及从别的项目导入,所以我们需要对场景的导入和导出有一个详细的了解 1: 场景是由美术人员搭建完成后提交给程序;2: 场景一般包 ...

  9. 建议大家使用Java 8 的日期、时间,而非java.util.Date

    建议大家使用Java 8 的日期.时间,而非java.util.Date. 详细原因见:如何在Java 8中愉快地处理日期和时间 总结一下就是, java.util.Date 太乱,如 月份从0开始. ...

  10. 用Visual C#创建Windows服务程序

    一.Windows服务介绍: Windows服务以前被称作NT服务,是一些运行在Windows NT.Windows 2000和Windows XP等操作系统下用户环境以外的程序.在以前,编写Wind ...