Can't run mysql console via ssh after restarting service - mysql

I use Ubuntu 12.04 x64, currently with Mysql 5.5.28 (plus Galera, but I don't think it's related).
I made some changes in my.cnf, but changes was related to InnoDB settings (a lot more memory for the buffer pool, flush, thread concurrency settings etc.).
After that when I hit service mysql restart I cannot enter mysql console - I get following error message:
Lost connection to MySQL server at 'reading initial communication packet',
system error: 104
Sometimes next try results in entering console, sometimes not and I have to restart my SSH connection. What could be the problem and how to fix it?
EDIT:
I noticed that most of the time after the system error: 104 following error occurs:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket
'/var/run/mysqld/mysqld.sock' (111)
After few times it usually starts. Unfortunately now it didn't and in syslog there is:
Error in my_thread_global_end(): 2 threads didn't exit
Restarting SSH connection / MySQL server is not working. I can try reboot server but I'd try to resolve this without that step. Its testing environment so I want to find better solution than restart whole server ;)

Please try the answers in this page:- Lost connection to MySQL server at 'reading initial communication packet', system error: 0
Also try this.

Related

MYSQL databases refusing to be accesed after reboot

Every time I reboot my computer and try to access my mysql database it produces the following error:
ERROR 2002 (HY000):
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
any ideas on how to resolve this?
It might be that your MySQL is not started automatically on system start-up. Kindly execute mysqld to start the MySQL.
Or please refer https://askubuntu.com/questions/416309/start-mysql-on-startup, to start MySQL on system start-up, assuming that you are on Linux OS.

Error while connecting to remote database server from container

I have a service deployed in mesos, which queries a remote database server. I used github.com/go-sql-driver/mysql to query the database from my Go code. It was working fine for about a week. But today I got this error: driver: bad connection
So I entered the docker container where my service runs and type in command line:
mysql -uxxx -hx.x.x.x -Pxxx -Dxxx -pxxx
Here's the response:
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
This is the content of /etc/mysql/my.cnf file:
[mysql]
no-auto-rehash # Faster start of mysql but no tab completition
What can be the error here? And how can I solve this?
Edit: When I run the same command from my local machine it works fine. I can query the database from the command line of my pc.

Keep Getting MySQL error of 'reading initial communication packet', system error: 111

I know this is a common issue. But I shut the DB server down with the Unix "service mysqld stop" command then restarted the server soon after with the "service mysqld start" command. I did it to flush out a couple of "killed" MySQL processes.
Checking, I get the
service mysqld status
mysqld (pid 19354) is running...
But on my webpages that access the DB I get the error "The Database Connection Is Down: Lost connection to MySQL server at 'reading initial communication packet', system error: 111"
So all I did was shut the DB server down and started it up again a minute later. How long will the problem persist, or is there more I should do?
Your host is wrong, your port is wrong, a firewall blocked the connection, or the SQL server is not running. 111 is "connection refused". You can troubleshoot by trying to telnet to the SQL server's host and port. If that works, your code gets the host or port wrong.
If that doesn't work, check on the SQL server itself. If it works there, the problem is the network. If it doesn't work there, the SQL server is not running.
Be sure the mysql is running: service mysqld status or try with PHPmyadmin

Mysql error 2002 after server shutdown

The server had shut down yesterday because electricity had cut off. After that, I've tried connect to Mysql but only got the 2002 error related with mysql.sock. Anyway, I've fixed the issue with this solution:
Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (38)
sudo chmod -R 755 /var/lib/mysql/
But my question is: Why? Why a shutdown caused this error? How prevent this from happening again?
Check the '/var/log/mysqld.log' first to see messages on file/directory permission
If the MySQL server terminated unexpectedly, the MySQL socket was not reset after the reboot
Due to power shutdown, the existing mysql process got terminated and socket file is not removed properly as this is not a graceful shutdown. The MySQL server no longer attempts to verify the existence of a MySQL socket when the socket is not being used by any processes as the block checking for socket existence should only matter if there's a PID attached to the other end of the socket. On unclean reboot, this socket will persist and thus cause the failure.
Solution :
I guess the simplest thing to do is remove the socket check. If there's no mysqld pids, then the existence of the socket may not be a useful check
Why a shutdown caused this error?
The error indicates that MySQL was not bound to its socket. It probably wasn't able to bind to its socket because it appeared that another process (namely the MySQL instance that did not shutdown cleanly) was still bound thereto.
How prevent this from happening again?
Install a UPS (uninterruptible power supply), which can provide backup power (from batteries) whilst signalling to the server that primary power has failed. This gives the server an opportunity to cleanly shutdown, so that its files are not left in a corrupt state.

My SQL Database error

I was running a successful (drupal) site using Mysql (I'm on Mac OS X) until I suddenly started to get the following error: "PDOException: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in db_table_exists()"
I don't know what this means or how to fix it, but when I visit phpmyadmin I get the following message: "#2013 - Lost connection to MySQL server at 'reading initial communication packet', system error: 61"
#Mitch: I installed it using the acquia drupal dev desktop stack, although I also have MAMP installed. I tried restarting the servers using these programs and this is the error I got (above). Can you perhaps provide more detailed instructions? Thanks.
It means your database is off (or crashing). You need to restart it. This will vary depending on how you installed MySQL.
You probably need to comment out the bind address in my.conf.
edit: no, seriously.
SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql.sock'
means MySQL can't be connected through the socket file.
Check if /tmp/mysql.sock is present (including permissions), if not check your my.cnf where it is (or run mysql_config --socket).
So you can either make a symbolic link or alternatively specify unix_socket path in your settings.php file ('unix_socket' => '/tmp/mysql.sock',).