[乐意黎原创]MySQL Error: SQLSTATE[HY000] [2002] Connection refused和The server quit without updating PID

MySQL Error: SQLSTATE[HY000] [2002] Connection refused


解决:

 /usr/local/mysql/bin/mysqld_safe --user=mysql & (启动mysql)

killall mysqld -9(重启mysql)

killall mysqld(关闭mysql)


[[email protected] ~]# systemctl stop mysqld
[root@aerchi.com ~]# /usr/local/mysql/bin/mysqld_safe --user=root &
[1] 22090
[root@aerchi.com ~]# 2018-06-25T10:45:52.106908Z mysqld_safe Logging to '/usr/local/mysql/logs/mysqld.log'.

2018-06-25T10:45:52.126600Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

[root@aerchi.com ~]# killall mysqld -9
[root@aerchi.com ~]# /usr/local/mysql/bin/mysqld_safe: line 198: 22561 Killed                  nohup /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=root --log-error=/usr/local/mysql/logs/mysqld.log --pid-file=/var/run/mysqld.pid < /dev/null > /dev/null 2>&1
2018-06-25T10:51:44.105560Z mysqld_safe Number of processes running now: 0
2018-06-25T10:51:44.110274Z mysqld_safe mysqld restarted



另:
/usr/local/mysql/bin/mysqld_safe: line 198: 23470 Killed            nohup /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=root --log-error=/usr/local/mysql/logs/mysqld.log --pid-file=/var/run/mysqld.pid < /dev/null > /dev/null 2>&1 > /dev/null 2>&1 > /dev/null 2>&1 > /dev/null 2>&1 > /dev/null 2>&1 > /dev/null 2>&1 > /dev/null 2>&1 > /dev/null 2>&1 > /dev/null 2>&1
2018-06-25T11:13:00.053559Z mysqld_safe Number of processes running now: 0
2018-06-25T11:13:00.142445Z mysqld_safe mysqld restarted

解决方法:

vi /etc/security/limits.conf

*      soft    nproc           65535
*      hard    nproc           65535
*      soft    nofile          65535

*      hard    nofile          65535

之后重启服务器。

[root@aerchi.com ~]# mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data


------------------------------

根据重启mysql 反馈的问题:

第一:查询是否 存在mysql 僵尸进程

#ps -ef |grep mysql*

关闭相关的mysql 僵尸进程。killall mysqld(关闭mysql)


 systemctl status mysqld
● mysqld.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
   Active: active (exited) since Mon 2018-06-25 19:18:36 CST; 17h ago
     Docs: man:systemd-sysv-generator(8)


service mysqld restart

MySQL server PID file could not be found!                  [FAILED]

Starting MySQL.The server quit without updating PID file (/[FAILED]l/mysql/data/i***r6Z.pid).


解决方法:
1. 修改 MySQL的my.cnf 文件

vim /etc/my.cnf

[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 datadir = /usr/local/mysql/data
 12
 13 [mysqld_safe]
 14 log-error=/usr/local/mysql/logs/mysqld.log
 15 #pid-file=/var/run/mysqld.pid
 16 pid-file=/usr/local/mysql/mysqld.pid
 17
 18 #
 19 # include all files from the config directory
 20 #
 21 #!includedir /etc/my.cnf.d
 22 max_connections = 2000

 23 max_user_connections = 1900

 24 max_connect_errors = 10000

 25 max_allowed_packet = 100M

 26 #实际是去除NO_ZERO_IN_DATE,NO_ZER  O_DATE
 27 disable-partion-engine-check = 1
 28 sql_mode = ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
 29 table_open_cache = 8000
 30 connect_timeout = 20
 31 wait_timeout=2880000
 32 interactive_timeout=2880000
 33 # aerchi.com
 
 34 innodb_buffer_pool_size = 128M
 35 key_buffer_size = 128M

 2. 移除 MySQL配置文件 /etc/my.cnf 注意备份

移除 my.cnf文件,注意备份

备份: mv /etc/my.cnf /etc/my.cnf.backup

重启: service mysqld start

Starting MySQL                                             [  OK  ]
[root@*6Z ~]# 2018-06-29T02:12:15.787884Z mysqld_safe A mysqld process already exists
 
 


以上内容,

------------------------------------------------------------------------------------------

当抛错时,应该查看MySQL的日志,

比如错误信息:2018-06-28T04:40:26.338321Z 0 [Note] InnoDB: Using CPU crc32 instructions

2018-06-28T04:40:26.339820Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2018-06-28T04:40:26.339855Z 0 [ERROR] InnoDB: mmap(137428992 bytes) failed; errno 12

2018-06-28T04:40:26.340077Z 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool

请修改my.cnf, 添加

 34 innodb_buffer_pool_size = 128M

 35 key_buffer_size = 128M


比如错误信息:

Starting MySQL.The server quit without updating PID file (/usr/local/mysql/data/***6Z.pid). 

在my.cnf配置文件中的 [mysqld_safe] 下添加

 log-error = /apps/logs/mysql/error.log      # 表示mysql服务启动日志文件的位置,路径可自己更改

 最后发现根源是操作系统未安全关机,MySQL未能安全关闭,而系统表是用myisam引擎的,myisam不支持崩溃修复损坏,然后导致系统表损坏,而启动又检查myisam-recover,无法recover就无法启动了。 

提示: MySQL启动时出现:Starting MySQL.The server quit without updating PID file (/usr/local/mysql/data/***6Z.pid). 

请注意重启(reboot)即可解决。



# systemctl restart mysqld

Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.


# systemctl status mysqld.service -l

● mysqld.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2018-06-28 17:01:27 CST; 1min 19s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 2576 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=1/FAILURE)


Jun 28 17:01:26 *6Z systemd[1]: Starting LSB: start and stop MySQL...
Jun 28 17:01:27 *6Z mysqld[2576]: Starting MySQL.The server quit without updating PID file (/usr/local/mysql/data/*6Z.pid).[FAILED]
Jun 28 17:01:27 *6Z systemd[1]: mysqld.service: control process exited, code=exited status=1


Jun 28 17:01:27 *6Z systemd[1]: Failed to start LSB: start and stop MySQL.
Jun 28 17:01:27 *6Z systemd[1]: Unit mysqld.service entered failed state.
Jun 28 17:01:27 *6Z systemd[1]: mysqld.service failed.

解决方法:

可能是/usr/local/mysql/data/mysql.pid文件没有写的权限

解决方法 :给予权限,执行 “chown -R mysql:mysql /var/data” “chmod -R 755 /usr/local/mysql/data”  然后重新启动mysqld!

 #/etc/init.d/mysqld status
MySQL is not running, but lock file (/var/lock/subsys/mysql[FAILED]


rm -rf /var/lock/subsys/mysql

-----------------------------------------------------------------

ervice mysqld restart
MySQL server PID file could not be found!                  [FAILED]
Starting MySQL.2018-06-29T06:52:45.424469Z mysqld_safe error: log-error set to '/usr/local/mysql/logs/mysqld.log', however file don't exists. Create writable for user 'mysql'.

The server quit without updating PID file (/usr/local/mysql/data/iZwz99mho1vp798njmvvr6Z.pid).                                             [FAILED]

[root@*6Z ~]# touch /usr/local/mysql/logs/mysqld.log

[root@*6Z ~]# chown -R mysql:mysql /usr/local/mysql/logs/

------------

[root@*6Z ~]#touch /usr/local/mysql/data/mysqld.pid
[root@*6Z ~]# touch /usr/local/mysql/data/mysqld.pid
[root@*6Z ~]# service mysqld restart

--------------------------------------------------------------------------------

 service mysqld start
Starting MySQL                                             [  OK  ]
# 2018-06-29T15:12:57.189830Z mysqld_safe A mysqld process already exists

ps -ef|grep mysql
kill -9 mysql进程

service mysqld start
Starting MySQL                                             [  OK  ]

当出现 MySQL server PID file could not be found! , 请尝试做好my.cnf 备份并删除。

cp /etc/my.cnf~ /etc/my.cnf
rm -rf /etc/my.cnf

--------------------------------------------------------------------------------

重新启动  systemctl restart mysqld    / service mysqld start 

查看进程 ps -ef |grep mysql
root      6343     1  0 14:00 pts/1    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/***6Z.pid
mysql     6600  6343  1 14:00 pts/1    00:00:10 /usr/local/mysql/bin/mysqld .....data/***6Z.pid
root      7559  5728  0 14:13 pts/1    00:00:00 grep --color=auto mysql

再次查看日志正常了

乐意黎
2018-06-28

猜你喜欢

转载自blog.csdn.net/aerchi/article/details/80805888