# MySQL server has gone away

**URL:** <https://talk.openmrs.org/t/mysql-server-has-gone-away/17221>\
**Category:** Bahmni\
**Tags:** mysql\
**Created:** [March 28, 2018, 6:08pm UTC](https://talk.openmrs.org/t/mysql-server-has-gone-away/17221 "2018-03-28T18:08:14Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramashish](https://talk.openmrs.org/letter_avatar/ramashish/32/6_449c533f586939b6e5f246632a46421f.png) [@ramashish](https://talk.openmrs.org/u/ramashish)\
**Post date:** [March 28, 2018, 6:08pm UTC](https://talk.openmrs.org/t/mysql-server-has-gone-away/17221/1 "2018-03-28T18:08:14Z")

</div>

We are getting following error mysql\> show tables; ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect… Connection id: 12 Current database: openmrs

ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect… ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (111) ERROR: Can’t connect to the server

Restarting mysql or the server itself hasn’t helped. mysql starts in force mode but as readonly.

Any ideas?

---

<div class="post-metadata">

**Author:** ![tendomart](https://talk.openmrs.org/user_avatar/talk.openmrs.org/tendomart/32/6753_2.png) [@tendomart](https://talk.openmrs.org/u/tendomart)\
**Post date:** [March 28, 2018, 6:18pm UTC](https://talk.openmrs.org/t/mysql-server-has-gone-away/17221/2 "2018-03-28T18:18:43Z")

</div>

@ramashish It usually does that when you are providing the wrong connect information.look at bahmni connection credentials and retry.

---

<div class="post-metadata">

**Author:** ![ramashish](https://talk.openmrs.org/letter_avatar/ramashish/32/6_449c533f586939b6e5f246632a46421f.png) [@ramashish](https://talk.openmrs.org/u/ramashish)\
**Post date:** [March 28, 2018, 6:20pm UTC](https://talk.openmrs.org/t/mysql-server-has-gone-away/17221/3 "2018-03-28T18:20:48Z")

</div>

How do I check bahmni connection credentials? Bahmni does not run at all. OpenMRS able to login but Administration-\>Location Hierarchy gives JDBConnection error.

This error is seen even from mysql prompt

---

<div class="post-metadata">

**Author:** ![tendomart](https://talk.openmrs.org/user_avatar/talk.openmrs.org/tendomart/32/6753_2.png) [@tendomart](https://talk.openmrs.org/u/tendomart)\
**Post date:** [March 28, 2018, 6:21pm UTC](https://talk.openmrs.org/t/mysql-server-has-gone-away/17221/4 "2018-03-28T18:21:11Z")

</div>

It usually does that when you are providing the wrong connect information.

---

<div class="post-metadata">

**Author:** ![ramashish](https://talk.openmrs.org/letter_avatar/ramashish/32/6_449c533f586939b6e5f246632a46421f.png) [@ramashish](https://talk.openmrs.org/u/ramashish)\
**Post date:** [March 28, 2018, 6:21pm UTC](https://talk.openmrs.org/t/mysql-server-has-gone-away/17221/5 "2018-03-28T18:21:57Z")

</div>

Any specific file where I should be checking?

---

<div class="post-metadata">

**Author:** ![jwnasambu](https://talk.openmrs.org/user_avatar/talk.openmrs.org/jwnasambu/32/13543_2.png) [@jwnasambu](https://talk.openmrs.org/u/jwnasambu)\
**Post date:** [March 28, 2018, 6:25pm UTC](https://talk.openmrs.org/t/mysql-server-has-gone-away/17221/6 "2018-03-28T18:25:21Z")

</div>

I suppose he desires your guidance on how to check the bahmni connection credentials

---

<div class="post-metadata">

**Author:** ![tendomart](https://talk.openmrs.org/user_avatar/talk.openmrs.org/tendomart/32/6753_2.png) [@tendomart](https://talk.openmrs.org/u/tendomart)\
**Post date:** [March 28, 2018, 6:30pm UTC](https://talk.openmrs.org/t/mysql-server-has-gone-away/17221/7 "2018-03-28T18:30:22Z")

</div>

@ramashish can you look at this thread [error in uploading address-hierarchy](https://talk.openmrs.org/t/error-in-uploading-address-hierarchy/16982/15)

and [https://bahmni.atlassian.net/wiki/spaces/BAH/pages/53837974/List+Of+Configurable+Installation+Variables1](https://bahmni.atlassian.net/wiki/spaces/BAH/pages/53837974/List+Of+Configurable+Installation+Variables1) they may be of help.

FYI @darius

---

<div class="post-metadata">

**Author:** ![ramashish](https://talk.openmrs.org/letter_avatar/ramashish/32/6_449c533f586939b6e5f246632a46421f.png) [@ramashish](https://talk.openmrs.org/u/ramashish)\
**Post date:** [March 28, 2018, 6:56pm UTC](https://talk.openmrs.org/t/mysql-server-has-gone-away/17221/8 "2018-03-28T18:56:36Z")

</div>

This will not help as this is not related to the user id pwd issue. I am able to login to mysql. It throws error after login to mysql from command prompt.

---

<div class="post-metadata">

**Author:** ![tendomart](https://talk.openmrs.org/user_avatar/talk.openmrs.org/tendomart/32/6753_2.png) [@tendomart](https://talk.openmrs.org/u/tendomart)\
**Post date:** [March 29, 2018, 3:42am UTC](https://talk.openmrs.org/t/mysql-server-has-gone-away/17221/9 "2018-03-29T03:42:37Z")

</div>

@ramashish have you read through the post and the Bhamni documentation?And assuming you have done so which credentials are you using?

---

<div class="post-metadata">

**Author:** ![tendomart](https://talk.openmrs.org/user_avatar/talk.openmrs.org/tendomart/32/6753_2.png) [@tendomart](https://talk.openmrs.org/u/tendomart)\
**Post date:** [March 29, 2018, 3:47am UTC](https://talk.openmrs.org/t/mysql-server-has-gone-away/17221/10 "2018-03-29T03:47:36Z")

</div>

Anyways

The MySQL server has gone away (error 2006) has two main causes and solutions:

```
Server timed out and closed the connection. To fix, check that wait_timeout mysql variable in your my.cnf configuration file is large enough.

```

Server dropped an incorrect or too large packet. If mysqld gets a packet that is too large or incorrect, it assumes that something has gone wrong with the client and closes the connection.

To fix, you can increase the maximal packet size limit max\_allowed\_packet in my.cnf file, eg. set max\_allowed\_packet = 128M, then restart your MySQL server: sudo /etc/init.d/mysql restart

---

<div class="post-metadata">

**Author:** ![tendomart](https://talk.openmrs.org/user_avatar/talk.openmrs.org/tendomart/32/6753_2.png) [@tendomart](https://talk.openmrs.org/u/tendomart)\
**Post date:** [March 29, 2018, 3:51am UTC](https://talk.openmrs.org/t/mysql-server-has-gone-away/17221/11 "2018-03-29T03:51:09Z")

</div>

To know the “max\_allowed\_packet” variable size you can drop this query in your MySQL client,

{ SHOW VARIABLES like ‘max\_allowed\_packet’ } ,it will show you the current value ,then rectify it to a bigger value…

Hope this is helpful

---

<div class="post-metadata">

**Author:** ![ramashish](https://talk.openmrs.org/letter_avatar/ramashish/32/6_449c533f586939b6e5f246632a46421f.png) [@ramashish](https://talk.openmrs.org/u/ramashish)\
**Post date:** [March 29, 2018, 4:04am UTC](https://talk.openmrs.org/t/mysql-server-has-gone-away/17221/12 "2018-03-29T04:04:13Z")

</div>

I had tried this too. I think the value 128M has already been set in auto.cnf

---

<div class="post-metadata">

**Author:** ![tendomart](https://talk.openmrs.org/user_avatar/talk.openmrs.org/tendomart/32/6753_2.png) [@tendomart](https://talk.openmrs.org/u/tendomart)\
**Post date:** [March 29, 2018, 4:05am UTC](https://talk.openmrs.org/t/mysql-server-has-gone-away/17221/13 "2018-03-29T04:05:37Z")

</div>

@ramashish what have you tried?

---

<div class="post-metadata">

**Author:** ![ramashish](https://talk.openmrs.org/letter_avatar/ramashish/32/6_449c533f586939b6e5f246632a46421f.png) [@ramashish](https://talk.openmrs.org/u/ramashish)\
**Post date:** [March 29, 2018, 6:22am UTC](https://talk.openmrs.org/t/mysql-server-has-gone-away/17221/14 "2018-03-29T06:22:05Z")

</div>

Things we tried following and their results

1. Checked both log files - /var/log/mysqld.log and var/log/openmrs/openmrs.log did not have any relevant information. Ensured that the last successful backup gets restored on another machine.

2. Forced restart of mySQL - Restarted mySQL using

`innodb_force_recovery = 4`.

This restarted the mySQL server in Read Only mode which only confirmed that there is no other issue (uid, pwd, bahmni, openmrs etc.) other than some problem with the database itself.

1. mySQL check From CentOS command Prompt as mentioned [here](https://dev.mysql.com/doc/refman/5.6/en/rebuilding-tables.html):

`mysqlcheck -uuid -ppwd openmrs`

This showed OK for most tables till location\_tag where connection got terminated indicating that this table has some issue. When tried mysqlcheck on location\_tag\_map it showed Ok. So used

`mysqlcheck --repair -uuid -ppwd openmrs location_tag`

with no success ie connection got terminated. Tried

`Alter table location_tag ENGINE = InnoDB;`

which did not help either ie connection got terminated.

1. Restore specific table - Due to lack of repair from the last successful backup which was restored on another machine extracted location\_tag table using

`mysqldump -uuid -ppwd openmrs location_tag > location_tag.sql`

Restored it using `mysql -uuid -ppwd openmrs < location_tag.sql`

This also failed due to connection terminated.

1. Restore last successful backup - Using innodb\_force\_recovery = 4 started mysql and dropped openmrs database. Removed innodb\_force\_recovery = 4 and restarted mysql. Then restored the last successful backup.

This got successfully restored but need further investigation on why the repair options failed.
