Ad Widget

Collapse

failed: [2002] Can't connect to local MySQL server through socket

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • toypatrick
    Junior Member
    • Aug 2018
    • 8

    #1

    failed: [2002] Can't connect to local MySQL server through socket

    I am trying to install zabbix on Cento 7 uname -a 3.10.0-862.11.6.el7.x86_64.\

    Followed the below post to install and configure.


    My database configuration
    Logs:
    20100:20180820:184344.548 [Z3005] query failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) [select escalationid,actionid,triggerid,eventid,r_eventid, nextcheck,esc_step,status,itemid from escalations where triggerid is not null order by actionid,triggerid,itemid,escalationid]
    20100:20180820:184344.548 [Z3001] connection to database 'zabbixdb' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
    20100:20180820:184344.548 database is down: reconnecting in 10 seconds
    20103:20180820:184345.539 [Z3005] query failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) [select taskid,type from task order by taskid]
    20103:20180820:184345.539 [Z3001] connection to database 'zabbixdb' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
    20103:20180820:184345.540 database is down: reconnecting in 10 seconds

    MariaDB [(none)]> SELECT User, Db, Host from mysql.db;
    +--------+-----------+-----------+
    | User | Db | Host |
    +--------+-----------+-----------+
    | | test | % |
    | | test\_% | % |
    | zabbix | zabbix_db | localhost |
    | zabbix | zabbixdb | localhost |
    +--------+-----------+-----------+
    4 rows in set (0.00 sec)

    MariaDB [(none)]> show databases;
    +--------------------+
    | Database |
    +--------------------+
    | information_schema |
    | mysql |
    | performance_schema |
    | test |
    | zabbixdb |
    +--------------------+
    5 rows in set (0.00 sec)

    MariaDB [(none)]>

    ### Option: DBHost
    DBHost=localhost
    ### Option: DBName
    # For SQLite3 path to database file must be provided. DBUser and DBPassword are ignored.
    # DBName=
    DBName=zabbixdb
    ### Option: DBSchema
    # Schema name. Used for IBM DB2 and PostgreSQL.
    # DBSchema=
    ### Option: DBUser
    # DBUser=
    DBUser=zabbix
    ### Option: DBPassword
    DBPassword=redhat
    ### Option: DBSocket
    # DBSocket=/tmp/mysql.sock
    ### Option: DBPort
    # DBPort=3306
    ### Option: StartDBSyncers
    # Number of pre-forked instances of DB Syncers.
    # StartDBSyncers=4
    [root@monitoring zabbix]#
  • kloczek
    Senior Member
    • Jun 2006
    • 1771

    #2
    Try to connect not from (probably) root account but specify "mysql -u zabbix -p redhat".
    http://uk.linkedin.com/pub/tomasz-k%...zko/6/940/430/
    https://kloczek.wordpress.com/
    zapish - Zabbix API SHell binding https://github.com/kloczek/zapish
    My zabbix templates https://github.com/kloczek/zabbix-templates

    Comment

    • toypatrick
      Junior Member
      • Aug 2018
      • 8

      #3
      It works ..

      [root@monitoring ~]# mysql -u zabbix -p zabbixdb
      Enter password:
      Reading table information for completion of table and column names
      You can turn off this feature to get a quicker startup with -A

      Welcome to the MariaDB monitor. Commands end with ; or \g.
      Your MariaDB connection id is 1529
      Server version: 5.5.56-MariaDB MariaDB Server

      Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

      Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

      MariaDB [zabbixdb]>

      Comment

      • kloczek
        Senior Member
        • Jun 2006
        • 1771

        #4
        You are doing above from root account and if you have enabled SELinux it is not the same security context which zabbix server is using.
        Solutions:
        - add proper zabbix server SELinux definition
        - disable SELinux
        http://uk.linkedin.com/pub/tomasz-k%...zko/6/940/430/
        https://kloczek.wordpress.com/
        zapish - Zabbix API SHell binding https://github.com/kloczek/zapish
        My zabbix templates https://github.com/kloczek/zabbix-templates

        Comment

        • toypatrick
          Junior Member
          • Aug 2018
          • 8

          #5
          [root@monitoring ~]# cat /etc/selinux/config |grep -i disabled
          # disabled - No SELinux policy is loaded.
          SELINUX=disabled
          [root@monitoring ~]#

          The selinux was disabled from initial stage.

          Comment

          • kloczek
            Senior Member
            • Jun 2006
            • 1771

            #6
            Code:
            20100:20180820:184344.548 [Z3001] connection to database 'zabbixdb' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
            Check does your maiadb really provides unix socket on this path.
            http://uk.linkedin.com/pub/tomasz-k%...zko/6/940/430/
            https://kloczek.wordpress.com/
            zapish - Zabbix API SHell binding https://github.com/kloczek/zapish
            My zabbix templates https://github.com/kloczek/zabbix-templates

            Comment

            • toypatrick
              Junior Member
              • Aug 2018
              • 8

              #7
              Can you plz tell me how do I chck that .. Thanks for the support

              Comment

              • vnoc
                Senior Member
                • Sep 2017
                • 115

                #8
                Is the above reported issue sorted out.

                At present I am also facing the same problem

                Comment

                • tim.mooney
                  Senior Member
                  • Dec 2012
                  • 1427

                  #9
                  Originally posted by vnoc
                  At present I am also facing the same problem
                  Even though you're having the same issue, it might have been better to start a new thread and reference this one, rather than replying to a 2 year old forum thread that went dead.

                  Still, since you posted here, I'll try help.

                  What output do you get when you run this command:

                  egrep 'DBHost|DBSocket|DBPort' /etc/zabbix/zabbix_serverd.conf

                  If all 3 of them are commented out (# as the first character), then according to the *comments* in the config file, it's trying to use the mysql default for a local socket to connect to your database.

                  Can you connect to the database using the 'mysql' command line tool using the database name, user name, and password you've set in your zabbix_serverd.conf file? Something like:

                  sudo -u zabbix mysql -u your_zabbix_db_user_here --database=your_zabbix_db_name_here -p

                  Comment

                  • irshad
                    Junior Member
                    • Dec 2020
                    • 2

                    #10
                    Originally posted by tim.mooney

                    Even though you're having the same issue, it might have been better to start a new thread and reference this one, rather than replying to a 2 year old forum thread that went dead.

                    Still, since you posted here, I'll try help.

                    What output do you get when you run this command:

                    egrep 'DBHost|DBSocket|DBPort' /etc/zabbix/zabbix_serverd.conf

                    If all 3 of them are commented out (# as the first character), then according to the *comments* in the config file, it's trying to use the mysql default for a local socket to connect to your database.

                    Can you connect to the database using the 'mysql' command line tool using the database name, user name, and password you've set in your zabbix_serverd.conf file? Something like:

                    sudo -u zabbix mysql -u your_zabbix_db_user_here --database=your_zabbix_db_name_here -p
                    I also face similar problem, the connection gets lost time to time, error appears at random interval. I followed your seteps (quoted) , and able to connect using the parameters configured in the zabbix_server.conf file

                    Comment

                    Working...