error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' — Missing /var/run/mysqld/mysqld.sock

后端 未结 30 2217
日久生厌
日久生厌 2020-11-22 10:49

My problem started off with me not being able to log in as root any more on my mysql install. I was attempting to run mysql without passwords turned on... but whenever I

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

    I uninstalled mysql in Ubuntu 16.04 https://askubuntu.com/questions/172514/how-do-i-uninstall-mysql

    I reinstalled mysql https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-16-04

    This seemed to work.

    0 讨论(0)
  • 2020-11-22 11:33

    There is a bug on Ubuntu with MySQL 5.6 and 5.7 where var/run/mysqld/ would disappear whenever MySQL service stopped or is rebooted. This prevents MySQL from running at all. Found this workaround, which isn't perfect, but at least it gets it running after stopping/reboot:

    mkdir /var/run/mysqld/
    chown mysqld /var/run/mysqld/
    
    0 讨论(0)
  • 2020-11-22 11:35

    Make sure your inaccessible socket file path is same as '/var/run/mysqld/mysqld.sock', otherwise change the path as yours. Stop the mysqld

    $ sudo /etc/init.d/mysqld stop
    

    If the process still runing;

    $ sudo pkill -9 mysqld
    

    Remove the mysql directory where socket going to create. For me it did not allowed to remove, so I had to forcefully remove.

    $ sudo mkdir -p /var/run/mysqld
    

    Set the ownership to the dirctory

    $ sudo chown mysql:mysql /var/run/mysqld
    

    Start mysql

    $ sudo /etc/init.d/mysql start
    

    Trying to connect mysql

    $ sudo mysql -u dbuser -p
    
    0 讨论(0)
  • 2020-11-22 11:36

    I had similar problem on a CentOS VPS. If MySQL won't start or keeps crashing right after it starts, try these steps:

    1) Find my.cnf file (mine was located in /etc/my.cnf) and add the line:

    innodb_force_recovery = X

    replacing X with a number from 1 to 6, starting from 1 and then incrementing if MySQL won't start. Setting to 4, 5 or 6 can delete your data so be carefull and read http://dev.mysql.com/doc/refman/5.7/en/forcing-innodb-recovery.html before.

    2) Restart MySQL service. Only SELECT will run and that's normal at this point.

    3) Dump all your databases/schemas with mysqldump one by one, do not compress the dumps because you'd have to uncompress them later anyway.

    4) Move (or delete!) only the bd's directories inside /var/lib/mysql, preserving the individual files in the root.

    5) Stop MySQL and then uncomment the line added in 1). Start MySQL.

    6) Recover all bd's dumped in 3).

    Good luck!

    0 讨论(0)
  • 2020-11-22 11:38

    Okay just copy and paste these codes: This should be done in the terminal, inside a server, when your mysql database is not properly installed, and when you are getting this error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'.

    Stop MySql

    sudo /etc/init.d/mysqld stop
    

    Restart it or start it

    sudo /etc/init.d/mysqld restart or sudo /etc/init.d/mysqld start
    

    Make a link like this and give it to the system

    ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
    

    Run a secure installation which guides all the process you need to do to configure mysql

    /usr/bin/mysql_secure_installation
    
    0 讨论(0)
  • 2020-11-22 11:40

    Just Need to Start MySQL Service after installation:

    For Ubuntu:

    sudo service mysql start;
    

    For CentOS or RHEL:

    sudo service mysqld start;
    
    0 讨论(0)
提交回复
热议问题