Steven
Steven

Reputation: 565

Could not connect: Lost connection to MySQL server at 'reading initial communication packet', system error: 0

I am running a Rails app so now I am trying to remote connect to MySQL and I am getting this error:

Could not connect: Lost connection to MySQL server at 'reading initial communication packet', system error: 0

Upvotes: 16

Views: 83263

Answers (11)

Ben
Ben

Reputation: 11

mysqld-max: ALL : ALLOW 

solved the problem for me.

Upvotes: 1

Federico Jaramillo
Federico Jaramillo

Reputation: 51

Enable remote access.

The MySQL server does not listen on the TCP port 3306 by default. To allow (remote) TCP connections, comment the following line in /etc/mysql/my.cnf:

skip-networking

Remember to edit /etc/hosts.allow by adding the following lines:

mysqld: ALL : ALLOW

mysqld-max: ALL : ALLOW

Upvotes: 4

vinayb21
vinayb21

Reputation: 535

OS: macOS

MySQL version: 5.7

Killed the current mysql service process

mysql.server stop

and started it again

mysql.server start

This solve the issue for me.

Upvotes: 1

Wojtek Kruszewski
Wojtek Kruszewski

Reputation: 14720

Using OS X? Does this issue go away for a while after mysqld restart and then re-appear? Check mysql server logs when getting these errors. I'm seeing a bunch of entries like below:

2019-01-30T17:34:04.009979Z 0 [Warning] File Descriptor 1564 exceeded FD_SETSIZE=1024

This error points to potential solutions: https://expressionengine.com/blog/mysql-5.7-server-os-x-has-gone-away https://wilsonmar.github.io/maximum-limits/

One of them is adding following setting to my.cnf

[mysqld]
table_open_cache=250

Upvotes: 3

d1jhoni1b
d1jhoni1b

Reputation: 8025

As we all know there are many different ways to install and configure mySQL dbms (database managment system) on our machines besides the fact we all run different OS (linux, osx, win$hit, etc)

In my case in particular i was getting

connect': Lost connection to MySQL server at 'reading initial communication packet', system error: 102 (Mysql2::Error)

BUT i did not even had /etc/hosts.deny i only had /etc/hosts because i installed mySQL on my OSX machine using simple GUI OSX app

enter image description here MySQL instance status was NOT OK above's image is just a reference for MySQL OSX APP.

Simple server re-start solved the issue.(in my case had to reboot my machine but that involves rebooting the MySQL server)

I was finally able to reach my localhost instance just fine again, did not had to change, create single file.

Hope this helps, i see Malcolm's answer and comments and made me think it was good to post this.

Upvotes: 1

Jason FB
Jason FB

Reputation: 5930

Nobody has seemed to answer this, and it appears to have re-emerged as an issue nearly 7 years after originally being filed. I saw this on Rails app running Capybara (using phantomjs), my integration specs (only) would intermittently fail with this.

Restarting the machine temporarily fixed the problem.

I then imploded my MySQL installation completely (see https://community.jaspersoft.com/wiki/uninstall-mysql-mac-os-x) and re-installed it using homebrew. The problem appears to have gone away but I will update this answer if it comes back.

to implode your MySQL install completely (from https://community.jaspersoft.com/wiki/uninstall-mysql-mac-os-x):

Open a terminal window Use mysqldump to backup your databases to text files! Stop the database server

sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*

edit /etc/hostconfig and remove the line MYSQLCOM=-YES-

rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /private/var/db/receipts/*mysql*

Upvotes: 1

Malcolm
Malcolm

Reputation: 121

Rebooting the server worked for me. No settings changes needed.

Upvotes: 8

Roch
Roch

Reputation: 22041

You need to edit your mysql Configuration file, by default the bind-adress is set to 127.0.0.1.

Open: /etc/mysql/my.cnf

Change the bind-adress to the ip you are going to use to connect yoursef to the database server.

Upvotes: 3

jlg
jlg

Reputation:

You might want to check your /etc/hosts.deny where:

ALL: ALL: DENY

or

mysqld: ALL: DENY

is your enemy.

Upvotes: 11

Steven
Steven

Reputation: 565

Thank you guys for your effort, I have found the solution, I was suppose to set Remote Connection to MySQLhere is the link for someone who got the same error http://benrobb.com/2007/01/15/howto-remote-root-access-to-mysql/

Upvotes: 0

noonex
noonex

Reputation: 2075

check from that host

shell> telnet IP 3306

If MySQL is up and reachable you'll see mysql version in telnet output. Otherwise check firewall, etc until telnet succeeds.

Then I advice you first connect with native mysql client to exclude Rails from problem aria.

Upvotes: 4

Related Questions