---
title: "源码安装的MySQL强制关闭后起不来，解决"
author: "forrest_lv"
date: "2016-01-13T01:03:55Z"
tags: []
categories: ["数据库"]
slug: "mysql"
draft: false
lastmod: "2016-01-13T01:06:59Z"
id: 2270205
url: "https://forrest-lv.iteye.com/blog/2270205"
---

我强制关掉mysqld进程后，起不来，修改my.cnf文件后就OK了：

安装是按照[http://forrest-lv.iteye.com/admin/blogs/2260703](/admin/blogs/2260703) 安装的

之前的启动都是ok，/etc/my.cnf配置没影响到，但是强制关闭后，就受到/etc/my.cnf影响了

 

查看/var/log/mysqld.log文件，是说 mysqld.pid 找不到，但是又怀疑是“创建了mysqld.pid，中间出问题，然后删掉mysqld.pid了，再去找mysqld.pid” 。

但是经过下面修改，就ok了。。

\[root@centos65 ~]# cat /etc/my.cnf

\[mysqld]

datadir=/opt/softwares/mysql\_5\_7\_9/data

socket=/var/lib/mysql.sock

user=laolv

\# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

 

\[mysqld\_safe]

datadir=/opt/softwares/mysql\_5\_7\_9/data

socket=/var/lib/mysql.sock

user=laolv

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

**#pid-file=/var/run/mysqld/mysqld.pid 注意注释掉pid-file很重要**

 

\[laolv@centos65 mysql\_5\_7\_9]$ pwd

/opt/softwares/mysql\_5\_7\_9

\[laolv@centos65 mysql\_5\_7\_9]$ bin/mysqld\_safe --user=laolv

160112 16:16:12 mysqld\_safe Logging to '/var/log/mysqld.log'.

160112 16:16:12 mysqld\_safe Starting mysqld daemon with databases from /opt/softwares/mysql\_5\_7\_9/data

 

\[laolv@centos65 mysql\_5\_7\_9]$ lsof -i:3306

COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

mysqld  10432 laolv   16u  IPv6  44725      0t0  TCP \*:mysql (LISTEN)

\[laolv@centos65 mysql\_5\_7\_9]$ ps -ef | grep -i 10432

laolv    10432 10253  0 16:16 pts/1    00:00:00 /opt/softwares/mysql\_5\_7\_9/bin/mysqld --basedir=/opt/softwares/mysql\_5\_7\_9 --datadir=/opt/softwares/mysql\_5\_7\_9/data --plugin-dir=/opt/softwares/mysql\_5\_7\_9/lib/plugin --user=laolv --log-error=/var/log/mysqld.log --pid-file=/opt/softwares/mysql\_5\_7\_9/data/centos65.pid --socket=/var/lib/mysql.sock

laolv    10704  3259  0 16:18 pts/0    00:00:00 grep -i 10432

 

**另外关闭数据库，和登录需要手动指定socket=/var/lib/mysql.sock文件**

\[laolv@centos65 mysql\_5\_7\_9]$ cat mylogin.sh 

mysql -uroot -p --socket=/var/lib/mysql.sock

\[laolv@centos65 mysql\_5\_7\_9]$ cat myshutdown.sh 

bin/mysqladmin -uroot -p shutdown --socket=/var/lib/mysql.sock

 

登录测试

\[laolv@centos65 mysql\_5\_7\_9]$ ./mylogin.sh 

mysql: \[Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \\g.

Your MySQL connection id is 2

Server version: 5.7.9 MySQL Community Server (GPL)

 

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\\h' for help. Type '\\c' to clear the current input statement.

 

mysql&gt; show databases;

+--------------------+

| Database           |

+--------------------+

| information\_schema |

| db1                |

| hivemeta           |