Unable to connect to mysql database
I get this error, I tried with check of user permission and password in user mysql table but the error persist.
root@vps [~]# /etc/cron.hourly/modsecparse.pl
DBI connect('modsec:localhost','modsec',...) failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) at /etc/cron.hourly/modsecparse.pl line 19
Unable to connect to mysql database at /etc/cron.hourly/modsecparse.pl line 19.
-
Are you sure MySQL itself is not down? Try "telnet localhost 3306" if you are unsure. If that is responding then exit the telnet and continue troubleshooting. At the top of /etc/cron.hourly/modsecparse.pl you should see something like this: my $dbhost = 'localhost'; my $dbuser = 'modsec'; my $dbpassword = '20h0j24hg039u4g'; my $dbname = 'modsec'; my $tblname = 'modsec'; At root SSH prompt try this: # mysql -u modsec -p You should get a prompt "Enter password;", enter the my $dbpassword password like 20h0j24hg039u4g This should connect to MySQL, The MySQL prompt should let you do this: mysql> show databases ; +--------------------+ | Database | +--------------------+ | information_schema | | modsec | +--------------------+ 2 rows in set (0.00 sec)
If you get an error from mysql -u modsec -p when trying to connect then likely the username/password is wrong, and you need to manually re-set the password for 'modsec' to match the password in modsecparse.pl if you can connect to MySQL but the database 'modsec' does not show from "show databases ; " then the database is missing or the modsec user is not granted permissions.0 -
this is result root@vps8 [~]# telnet localhost 3306 Trying ::1... telnet: connect to address ::1: Connection refused Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. 8 5.1.73-cll+pU:_PS.:vi)0S2>$7(_PuTTY [COLOR="silver">- - - Updated - - - with 127.0.0.1 the result is root@vps8 [~]# telnet 127.0.0.1 3306 Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is '^]'. 8 [COLOR="silver">- - - Updated - - - I set my $dbhost = '127.0.0.1';, now the script work fine, but If I load mod security page on WHM this is the error: Mod Security Click here for important information about mod_security versions and rules The mod_security plugin could not connect to the database. Please verify that MySQL is running. Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 0 -
Hello :) Please see the following post: Modsec Database Failure Also, please let us know the output from: grep skip /etc/my.cnf
Thank you.0 -
Same problem here. Notice that it started when Mysql updated to V5.1.73 according to the timestamp on /var/lib/mysql/mysql_upgrade_info (and assuming it was updated at that time as the contents of the file are simply 5.1.73 ) I have verified that I can connect to the database as the user. The error message states that the modsecparse.pl script is trying to connect to the socket at /tmp/mysql.sock, but the location of the socket is /var/lib/mysql/mysql.sock Personally, I hate changing any cpanel script to get around this (or any other cpanel issues) as the next cpanel update might simply over-write it and I would be back to fixing it again. For those that don't want to wait the hack is actually trivial - on line 13 - comment it out and force it to use the socket at the correct location. # my $dbhost = 'localhost'; my $dbhost = 'mysql_socket=/var/lib/mysql/mysql.sock';
Ideally, the script SHOULD, rather than use a localhost connection, is to determine the actual location of the socket file, then set the value. But at least for now, until this script is updated, I will stop getting these annoying cron job messages. Output before modificationroot@host [/]# /etc/cron.hourly/modsecparse.pl DBI connect('modsec:localhost','modsec',...) failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) at /etc/cron.hourly/modsecparse.pl line 19 Unable to connect to mysql database at /etc/cron.hourly/modsecparse.pl line 19. root@host [/]#
Output AFTER modificationroot@host [/]# /etc/cron.hourly/modsecparse.pl root@host [/]#0 -
Could you submit a bug report so the issue is addressed accordingly? Submit A Bug Report You can post the ticket number here so we can update this thread with the outcome. Thank you. 0 -
On my system, /tmp/mysql.sock is just a symlink to /var/lib/mysql/mysql.sock, and I did not create this symlink. Perhaps your symlink was missing for some reason. lrwxrwxrwx 1 root root 30 Mar 14 16:50 mysql.sock -> ../../var/lib/mysql/mysql.sock= Most likely you could just: cd /tmp ln -s ../../var/lib/mysql/mysql.sock mysql.sock
If I remove the symlink I get the connection error, when I recreate it everything is fine. No editing of the /etc/cron.hourly/modsecparse.pl was required.0 -
[quote="quizknows, post: 1596421">On my system, /tmp/mysql.sock is just a symlink to /var/lib/mysql/mysql.sock, and I did not create this symlink. Perhaps your symlink was missing for some reason. lrwxrwxrwx 1 root root 30 Mar 14 16:50 mysql.sock -> ../../var/lib/mysql/mysql.sock= Most likely you could just: cd /tmp ln -s ../../var/lib/mysql/mysql.sock mysql.sock
If I remove the symlink I get the connection error, when I recreate it everything is fine. No editing of the /etc/cron.hourly/modsecparse.pl was required.
Well, that in itself is a bug as far as I am concerned. Nothing within /tmp should be critical to the operation and is a Temporary File - so yes, if there has been a sym-link to the socket file in the past, then this has been a problem for a lot longer than the last several days. All in all, this is a bug within the script that does not properly identify the location of the socket (and no, a sym-link is not the location of the socket) or correctly use a network connection (loopback) to the db. [COLOR="silver">- - - Updated - - - [quote="cPanelMichael, post: 1596102">Could you submit a bug report so the issue is addressed accordingly? Submit A Bug Report You can post the ticket number here so we can update this thread with the outcome. Thank you.
Bug Report submitted that references this thread. Ticket 46738890 -
When connecting via localhost, if the symlink for /tmp/mysql.sock does not exist, the connection will fail. Internal case number 94101 has been opened to address the use of "localhost" instead of "127.0.0.1" in /etc/cron.hourly/modsecparse.pl. There is currently no specific time frame on if/when a change will be implemented. Thank you. 0 -
I've just run into this after a reboot for a kernel upgrade. Restarting mysql via the script for doing so put the symlink into tmp, As normal (by the looks from boot.log) the secure tmp was set up before mysql started. Having issued another reboot can't reproduce the problem, subscribing in case anyone finds the root cause. 0 -
[quote="quizknows, post: 1596421"> cd /tmp ln -s ../../var/lib/mysql/mysql.sock mysql.sock
Same issue here after rebooting from a kernel update and fixed by adding the symlink back.0 -
Unfortunately, not fixed. CP just updated to 11.44.x a re-build of Apache and yep, had to re-apply the fix. How hard is it to actually parse the my.cnf file to find the configured location of a socket file rather than wrongly relying on something in /tmp Have you not heard of tmpwatch people? Heck, even if there was a sym-link from /tmp to the correct location of the socket chances are it would not survive more than a day! 0 -
[quote="rrwh, post: 1676932">Unfortunately, not fixed. CP just updated to 11.44.x a re-build of Apache and yep, had to re-apply the fix.
Please note that a resolution for internal case number 94101 has not yet been released. Thank you.0 -
I am having the same issue, and I don't seem to have any /tmp/mysql.sock file. Manually changing my $dbhost to point to 'mysql_socket=/var/lib/mysql/mysql.sock'; like rrwh mentioned above seems to work for now, but is there an official fix coming for this? Thanks! 0 -
I fixed this issue on my server by enable mysql monitoring in WHM >> service manager 0
Please sign in to leave a comment.
Comments
14 comments