0

I'm getting the following error for a couple of commands I'm trying to run AND I don't know the password whenever I'm prompted for that. (note: I just updated my ubuntu distribution to 22.04, but I previously didn't have a password set/had an empty password for 'root').

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

It seems from most posts that the common issue is that mysql-server isn't actually running. I can see that mine is running, though, with sudo service mysql status and the following commands return...

$ cat /etc/services | grep 3306
    mysql           3306/tcp
$  netstat -tulpn | grep 3306
    (No info could be read for "-p": geteuid()=1000 but you should be root.)
    tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      -
    tcp        0      0 127.0.0.1:33060         0.0.0.0:*               LISTEN  

These commands are giving the "Can't connect..." error:

  • mysqladmin -u root -p shutdown
  • mysqladmin version
  • mysql
  • mysql -u root
  • mysql -u root -h localhost -p

Running mysql -u root -h 127.0.0.1 -p seems to work in that it prompts me for a password, but none of my prior passwords are working and I have not been able to run sudo mysqld_safe --skip-grant-tables & or sudo mysqld_safe --skip-grant-tables --skip-networking & successfully to reset the root password.

I have also run...

Additional random info:

I also know that /var/run/mysqld/mysqld.sock did exist earlier in this process (I only have mysql.bak in that directory now), but when I run sudo find / -type s, it just returns a bunch of files/directories with "Permission Denied" (I assume because I'm in WSL), so I haven't checked that there could be another mysql.sock somewhere.

I also know that /etc/mysql/my.cnf is just pointing to -> /etc/alternatives/my.cnf, which only has the following in it (other than some comments):

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
  • Any progress? Does sudo mysql get you to a prompt without the server? If so, try this answer to reset the root password. – NotTheDr01ds Feb 05 '23 at 23:32
  • I finally got it to work. I removed mysql all over again and reinstalled. I was having trouble resetting the password for root, but I eventually got it. I think part of the issue may have been that I just didn't know that you have to use sudo when logging in as root... @NotTheDr01ds – coniferous Feb 06 '23 at 15:51
  • Cool - And yes, I believe (IIRC) that's because the local database file is owned by root. So until the server is running, accessing/modifying the local file will require sudo. – NotTheDr01ds Feb 06 '23 at 17:15
  • you can try sudo chmod 777 -R /var/run/mysqld/ – 白玄玉 Mar 30 '23 at 02:42

1 Answers1

0
  1. Stop MySQL (sudo systemctl stop mysql)
  2. Verify process is stopped
  3. Start MySQL with --skip-grant-tables

Alternativly purge mysql: sudo apt purge mariadb-server mysql-common Verify /etc/mysql and /var/lib/mysql are empty/ deleted

Reinstall

Uwe Burger
  • 642
  • 3
  • 3