设为首页 加入收藏

TOP

Can’t connect to MySQL Server实例解析(一)
2018-06-18 14:24:19 】 浏览:338
Tags:Can connect MySQL Server 实例 解析

查看mysql 日志:cat /var/log/mysqld.log查看 mysql 状态:netstat -anp | grep mysqld

确定IP, port可工作: telnet *.*.*.* port (telnet 192.168.233.142 3306)

远程访问mysql:mysql -u root -h *.*.*.* -p

打开https 端口

# http, https
  $iptables -A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
  $iptables -A OUTPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
  $iptables -A OUTPUT -p tcp -m state --state NEW --dport 443 -j ACCEPT

There are a lot of different reasons behind this error. Sometime, you may not see the exact issue on the error message. You have to dig deeper to identify the exact cause. It may take a lot of time and energy to debug this error. I have encountered this error many times, so based on my experience and research on this issue; I have gathered and given the following possible reasons and workarounds to fix this error.

Error Message:

Can't connect to local MySQL server

Reason 1:MySQL Server is not running on the server.

Workaround 1:Check MySQL server is running on the server.

MySQL process name : mysqldMySQL default port : 3306

On Linux:To check the service status : systemctl status mysqlTo check the process list : ps ax | grep mysqlTo check the listening port : netstat –anp | grep mysql

On Windows:To check the service status : Ctrl + R -> MySQLTo check the process list : Task Manager -> mysqld

If you are trying to connect to MySQL service running on remote server, use telnet.telnet 127.0.0.1 3306 (Replace the IP and Port)

If not running, start the MySQL service and try to connect to MySQL server. If MySQL is not starting, see the error log to find out the reason and fix the error. If this is the reason, the error could have resolved now.

Reason 2:MySQL socket file is missing / deleted / different location.

Workaround:MySQL server can be connected through either socket file or TCP/IP protocol. When you are trying to connect, MySQL service running on localhost, it will be connected through the socket file. If socket file missing, you will get error message with location of the file.

Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) when trying to connect.

Socket file is a special purpose file, it is used as interface to connect MySQL server from clients. This file is created automatically by the server. If the file is not exists, it is because either of the following issues:

MySQL server was not started.MySQL is created socket file in different location.Socket file unexpectedly removed / deleted /missing.MySQL service is started with socket variable but client trying to connect to default socket.

Example: mysqld –socket=/var/lib/mysqld.sock

If MySQL server is not started:

Use workaround 1 to verify MySQL is running or not. If MySQL service is not running, start the MySQL service by using the following method:

On Linux:

sudo systemctl start mysql

On Windows:

Go to services.msc and start MySQL service.

Note: you can also start the mysql service by other methods too.

If MySQL is created socket file but it is in different location / MySQL service is started with socket variable but client trying to connect to default socket.

You can use mysqladmin utility to check the current location of the MySQL socket file, as below:

mysqladmin -u root -h 127.0.0.1 -p version

When you connect it from client, you can specify the client explicitly using - -socket variable or change the socket file location in configuration file (This required service restart).

[mysqld]socket=/datadir/mysql.sock

If socket file is missing / removed /delete

首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇oracle存储过程selectinto没有查.. 下一篇JDBC连接MySQL报错Unknownsystemv..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目