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

后端 未结 30 2348
再見小時候
再見小時候 2020-11-22 04:23

I am having a big problem trying to connect to mysql. When I run:

/usr/local/mysql/bin/mysql start

I have the following error :

<         


        
相关标签:
30条回答
  • 2020-11-22 04:30

    I had this problem too when trying to start the server, so many of the answers here that just say to start the server didn't work. The first thing you can do is execute the following to see if there are any config errors:

    /usr/sbin/mysqld --verbose --help 1>/dev/null
    

    I did have one error that showed up:

    160816 19:24:33 [Note] /usr/sbin/mysqld (mysqld 5.5.50-0ubuntu0.14.04.1-log) starting as process 9461 ...
    160816 19:24:33 [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
    160816 19:24:33 [Note] Plugin 'FEDERATED' is disabled.
    160816 19:24:33 [ERROR] /usr/sbin/mysqld: unknown variable 'innodb-online-alter-log-max-size=4294967296'
    160816 19:24:33 [ERROR] Aborting
    

    A simple grep -HR "innodb-online-alter-log-max-size" /etc/mysql/ showed me exactly what file contained the offending line, so I removed that line from the file.

    Then, checking my /var/log/mysql/error.log file I had:

    InnoDB: Error: log file ./ib_logfile0 is of different size 0 5242880 bytes
    InnoDB: than specified in the .cnf file 0 671088640 bytes!
    160816 22:46:46 [ERROR] Plugin 'InnoDB' init function returned error.
    160816 22:46:46 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
    160816 22:46:46 [ERROR] Unknown/unsupported storage engine: InnoDB
    160816 22:46:46 [ERROR] Aborting
    

    Based on this question the accepted solution wouldn't work because I couldn't even get the server started, so I followed what some of the comments said and deleted my /var/lib/mysql/ib_logfile0 and /var/lib/mysql/ib_logfile1 files.

    This allowed the server to start and I was able to connect and execute queries, however checking my error log file it was quickly getting filled up with several tens of thousands of lines like this:

    160816 22:52:15  InnoDB: Error: page 1415 log sequence number 82039318708
    InnoDB: is in the future! Current system log sequence number 81640793100.
    InnoDB: Your database may be corrupt or you may have copied the InnoDB
    InnoDB: tablespace but not the InnoDB log files. See
    InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-recovery.html
    InnoDB: for more information.
    

    Based on a suggestion from here, to fix this I did a mysqldump and restore of all databases (see the link for several other solutions).

    $ mysqldump -u root -p --allow-keywords --add-drop-database --comments --hex-blob --opt --quote-names --databases db_1 db_2 db_3 db_etc > backup-all-databases.sql
    $ mysql -u root -p < backup-all-databases.sql
    

    Everything appears to be working as expected now.

    0 讨论(0)
  • 2020-11-22 04:32

    try with -h (host) and -P(port):

    mysql -h 127.0.0.1 -P 3306 -u root -p

    0 讨论(0)
  • 2020-11-22 04:34

    CentOS 7, 64 bit. Fresh installation.
    In my case, the error was because I didn't have the right MySQL server and MySQL client installed.
    Using yum, I removed mariadb and mysql-community edition. I downloaded the rpm's for the client and server from the official MySQL website and installed the server and client.

    On installing the server, I was shown a message that the password to the root account for MySQL was stored in a file which I could view with sudo cat /root/.mysql_secret.

    So after installing the client and server, I checked if MySQL was working (I think I rebooted before doing so) with the command sudo service mysql status and I got the result.

    MySQL running (2601) [ OK ]

    I logged into MySQL using the password from the .mysql_secret file:
    mysql -uroot -pdxM01Xfg3DXEPabpf. Note that dxM01Xfg3DXEPabpf is the password mentioned in the .mysql_secret file.

    and then typed entered the following command at the mysql prompt to change the password of root:

    mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('somePassword');

    Everything worked fine from then on.

    0 讨论(0)
  • 2020-11-22 04:34

    I had this socket error and it basically came down to the fact that MySQL was not running. If you run a fresh install, make sure that you install 1) the system package and 2) the panel installer (mysql.prefPane). The panel installer will allow you to goto your System Preferences and open MySQL, and then get an instance running.

    Note that, on a fresh install, I needed to reset my computer for the changes to properly take effect. Following a reboot, I got a new instance running and was able to open up a connection to localhost with no problem.

    Also of note, I apparently had previous versions of MySQL installed but had removed the panel, which makes it easy to get an instance of MySQL running for mac users.

    A good link for this process of reinstalling: http://www.coolestguyplanettech.com/how-to-install-php-mysql-apache-on-os-x-10-6/

    0 讨论(0)
  • 2020-11-22 04:35

    As can be seen by the many answers here, there are lots of problems that can result in this error message when you start the MySQL service. The thing is, MySQL will generally tell you exactly what's wrong, if you just look in the appropriate log file.

    For example, on Ubuntu, you should check /var/log/syslog. Since lots of other things might also be logging to this file, you probably want to use grep to look at mysql messages, and tail to look at only the most recent. All together, that might look like:

    grep mysql /var/log/syslog | tail -50

    Don't blindly make changes to your configuration because someone else said 'This worked for my system.' Figure out what is actually wrong with your system and you'll get a better result much faster.

    0 讨论(0)
  • 2020-11-22 04:35

    I also found that this was a permissions problem. I compared the MySQL files to a working install (both on Debian 6 squeeze) and had to make the following ownership changes (where mydatabase is any database(s) you have).

    Ownership mysql:mysql:

    chown mysql:mysql /var/lib/mysql
    chown mysql:mysql /var/lib/mysql/ib*
    chown mysql:mysql /var/lib/mysql/mydatabase
    chown mysql:mysql /var/lib/mysql/mydatabase/*
    chown mysql:mysql /var/lib/mysql/mysql/* 
    

    Ownership mysql:root:

    chown mysql:root /var/lib/mysql/mysql
    chown mysql:root /var/run/mysqld 
    

    Ownership mysql:adm:

    chown mysql:adm /var/log/mysql
    chown mysql:adm /var/log/mysql.err
    chown mysql:adm /var/log/mysql.log* 
    
    0 讨论(0)
提交回复
热议问题