Centos / directadmin无法通过socket'/var/lib/mysql/mysql.sock'连接到本地MySQL服务器(2)

Error connecting to MySQL: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 

使用DirectAdmin在我的CentOS VM上出现以下错误。

我已经尝试:重新启动服务,杀死服务并启动,修改/etc/my.cnf文件

目前我完全删除my.cnf文件,因为mysqld启动没有错误,如果我添加my.cnf文件,那么我得到以下错误:

 Starting MySQL.. ERROR! The server quit without updating PID file (/var/lib/mysql/hostname.pid). 

当我去看/var/lib/mysql/hostname.pid没有这样的文件。

我试过2个my.cnf文件:

 [mysqld] innodb_buffer_pool_size = 256M innodb_thread_concurrency = 4 innodb_flush_log_at_trx_commit = 2 innodb_flush_method=O_DIRECT thread_concurrency = 4 thread_cache_size = 4 table_cache = 256 query_cache_size = 128M query_cache_limit = 1M join_buffer_size = 256K tmp_table_size = 256M key_buffer = 32M innodb_autoextend_increment=256 max_allowed_packet = 16M max_heap_table_size = 256M read_buffer_size = 256K read_rnd_buffer_size=256k bulk_insert_buffer_size = 32M myisam_repair_threads = 1 interactive_timeout=30 wait_timeout=30 binlog_cache_size=256M tmpdir=/tmp max_connections = 400 socket=/var/lib/mysql/mysql.sock key_buffer_size=64M 

原my.cnf

 [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid 

编辑:

我使用原来的my.cnf,同时删除.pid和.sock,重启后我得到以下内容:

 [root@server ~]# service mysqld status ERROR! MySQL is not running, but PID file exists [root@server ~]# service mysqld status ERROR! MySQL is running but PID file could not be found 

很奇怪,即使我没有做任何其他的命令,然后你上面看到它突然开始运行。 查看/var/lib/mysqld/ .pid或.sock文件都不存在。

我相信MySQL并没有启动,因为它在启动的时候会“触动”这个文件,如果这个文件已经存在,那么这个文件就是安全的。 尝试删除该文件。

 # rm /var/lib/mysql/mysql.sock # service mysqld restart 

我之前也看到过同样的错误,并且每次删除该文件都会修复它。