Not the answer you need?
Register and ask your own question!

Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

petter5petter5 EntrantCurrent User Role Beginner
I'm trying to login to my percona installation to add a new database. - Ubuntu 16.04. The system is running fine, and my current website seems to work fine so the problem is to login from termian using mysql --host=localhost --user=root --password

I then get the error: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

Trying to fint the socket of mysql: sudo find / -type s gives: /run/mysqld/mysqld.sock
so i try ~# whereis mysql : mysql: /usr/bin/mysql /usr/lib/mysql /etc/mysql /usr/share/mysql /usr/share/man/man1/mysql.1.gz

the /etc/mysql/my.conf looks like:

# The Percona Server 5.7 configuration file.
#
#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
# Please make any edits and changes to the appropriate sectional files
# included below.
#
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/percona-server.conf.d/

the /etc/mysql/conf.d/ contains two files:
mysql.cnf looks like

[mysql]

and mysqldump.cnf looks like

[mysqldump]
quick
quote-names
max_allowed_packet = 16M

the etc/mysql/percona-server.conf.d/ contains 4 files


mysqld.cnf looks like

# Generated by Percona Configuration Wizard (http://tools.percona.com/) version REL5-20120208
# Configuration name ***** generated for ********************** at 2016-10-18 19:09:33

[mysql]

# CLIENT #
bind-address = 127.0.0.1
port = 3306
socket = /var/lib/mysql/mysql.sock

[mysqld]

# GENERAL #
user = mysql
default-storage-engine = InnoDB
socket = /var/lib/mysql/mysql.sock
pid-file = /var/lib/mysql/mysql.pid

# MyISAM #
key-buffer-size = 32M

# SAFETY #
max-allowed-packet = 16M
max-connect-errors = 1000000
skip-name-resolve
sql-mode = STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY
sysdate-is-now = 1
innodb = FORCE

# DATA STORAGE #
datadir = /var/lib/mysql/

# BINARY LOGGING #
log-bin = /var/lib/mysql/mysql-bin
expire-logs-days = 14
sync-binlog = 1
server-id = 12345

# CACHES AND LIMITS #
tmp-table-size = 32M
max-heap-table-size = 32M
query-cache-type = 0
query-cache-size = 0
max-connections = 500
thread-cache-size = 50
open-files-limit = 65535
table-definition-cache = 4096
table-open-cache = 32M

# INNODB #
innodb-flush-method = O_DIRECT
innodb-log-files-in-group = 2
innodb-log-file-size = 512M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table = 1
innodb-buffer-pool-size = 20G

# LOGGING #
log-error = /var/lib/mysql/mysql-error.log
log-queries-not-using-indexes = 1
slow-query-log = 1
slow-query-log-file = /var/lib/mysql/mysql-slow.log


the mysqld.cnf.backup looks like

# Generated by Percona Configuration Wizard (http://tools.percona.com/) version REL5-20120208
# Configuration name ******* generated for **************** at 2016-10-18 19:09:33

[mysql]

# CLIENT #
bind-address = 127.0.0.1
port = 3306
socket = /var/lib/mysql/mysql.sock

[mysqld]

# GENERAL #
user = mysql
default-storage-engine = InnoDB
socket = /var/lib/mysql/mysql.sock
pid-file = /var/lib/mysql/mysql.pid

# MyISAM #
key-buffer-size = 32M

# SAFETY #
max-allowed-packet = 16M
max-connect-errors = 1000000
skip-name-resolve
sql-mode = STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY
sysdate-is-now = 1
innodb = FORCE

# DATA STORAGE #
datadir = /var/lib/mysql/

# BINARY LOGGING #
log-bin = /var/lib/mysql/mysql-bin
expire-logs-days = 14
sync-binlog = 1
server-id = 12345

# CACHES AND LIMITS #
tmp-table-size = 32M
max-heap-table-size = 32M
query-cache-type = 0
query-cache-size = 0
max-connections = 500
thread-cache-size = 50
open-files-limit = 65535
table-definition-cache = 4096
table-open-cache = 32M

# INNODB #
innodb-flush-method = O_DIRECT
innodb-log-files-in-group = 2
innodb-log-file-size = 512M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table = 1
innodb-buffer-pool-size = 20G

# LOGGING #
log-error = /var/lib/mysql/mysql-error.log
log-queries-not-using-indexes = 1
slow-query-log = 1
slow-query-log-file = /var/lib/mysql/mysql-slow.log


the mysqld.cnf.dpkg-dist looks like:

#
# The Percona Server 5.7 configuration file.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
explicit_defaults_for_timestamp

log-error = /var/log/mysql/error.log

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_ALL_TABLES

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0


the mysqld_safe.cnf looks like:

#
# The Percona Server 5.7 configuration file.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld_safe]
thp-setting=never
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
nice = 0

It seems to me there is a misconfiguration causing the " ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) " error, giving wrong path to the mysql sock. This server is running a live site and I'm afraid or doing too much testing, possible making the site going down.

I have attached screen dump of file structure /etc/mysql It seems tro me that there is required o clean up a little bit here. Anyone that can fugure out what's worng ?

Comments

  • petter5petter5 Entrant Current User Role Beginner
    BUMP - anyone with a solution ?
  • lorraine.pocklingtonlorraine.pocklington Percona Community Manager Legacy User Role Patron
    Hi there, there are a couple of things to check:

    You can confirm the path to the socket by looking at netstat
    To just connect, you should be able to use
    --socket=/var/run/mysqld/mysqld.sock
    

    Do you have anything in the error log by any chance? I saw reports that you can get this error with a full disk (for example).
    And another post suggests to specify 127.0.0.1 instead of localhost in the connection.

    Did you restart the server after changing the config?
    If you have any more info, please let us have it? Thanks.
Sign In or Register to comment.

MySQL, InnoDB, MariaDB and MongoDB are trademarks of their respective owners.
Copyright ©2005 - 2020 Percona LLC. All rights reserved.