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

Hi,

I have successfully installed bench and bench is started properly as well. Also have installed the mariadb which is also successfully installed and when I start the mariadb and check the service status, it is showing me active.

But at the end I can get the below error:

Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

I checked and found that mysqld.sock file is not created. I checked in the /tmp but the file is not there as well.

Can anyone tell me that what I missed here and how can I fix it?

When I tried to run the server using 127.0.0.1:8001 or localhost:8001 it’s return me like not found. Is it something to related mariadb service connection error or what?

Could you please share a screenshot?
becuase Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) is not enough to understand problem!

Here is the screenshot, it is when I start the mariadb service.

This is the screenshot of bench start:

Are you able to connect to mysql through mysql -u root or bench mariadb?

No, when I tried to connect through mysql -u root, I got the same error as above.

Ok, then confirm few things
First: while installing, have you followed these steps

Second:
Check for mariadb error log
using this
sudo journalctl -u mariadb -n 50 --no-pager
or
sudo less /var/log/mysql/error.log

Last is to check if you’ve permission to create file
try

sudo mkdir -p /var/run/mysqld

When tried to install mysql_secure_installation, I got the same error when entered the password.

Could you please also check the error.log and permission of file creation

This is a error log file logs:

And also I checked the /var/run/mysqld file permission. Which is like below:

drwxr-xr-x 2 mysql root 60 Jun 17 09:52 mysqld

The /var/run/mysqld/ directory is owned by mysql:root, but it must be owned by mysql:mysql.
try below command to setup the permission for mysql:mysql

sudo chown mysql:mysql /var/run/mysqld

then restart service

sudo systemctl restart mariadb

and also check if socket file is created using sudo find /var/run -name mysqld.sock

The /var/run/mysqld/ directory permission changed to mysql but after restart the service of mariadb got the same error.

Also checked and there is no mysqld.sock is created.

Then it’s better to completely remove the mariadb and reinstall (if this is not a production server)

Hi @vineyrawat

As per your previous message, I have completely removed the mariadb from my system and installed it again. Now, mysqld.sock file is create properly. But now after start the mariadb server and tried to open the server using 127.0.0.1:8001 in browser still I getting not found. When I go to log file I can see this:

Is it still I missing something here?

Have you run this command?
sudo mariad-secure-installation

This command will automatically setup all necessary configurations and ask for password for root user to create

yes I run that command and given no to some of the question and yes in some of the question. Below is the command screenshot:

ok my mistake I tried to connect with mysql. But I am able to connect with mariadb and also check the user and everything there. But last thing when I entered the url in the browser after start the bench and mariodb I still get this one:

Have you created any site yet?

for this use can use
[your-site-name].localhost:[your-port]
for example local1.localhost:8001 if your sitename is local1.localhost

or you can just run below command it will set your site to default site and you’ll be able to access directly on localhost:8001

bench use [your-site-name] for example bench use site1.local

Based on the screenshot you provided, you selected n for Change the root password?. That’s fine if a root password is already set in your database. However, if there’s no existing root password, you’ll need to choose Y and set one. Without it, you won’t be able to create, migrate, or restore your sites.

I think it’s work to reach the site but it is showing me this error: