Home > database >  How can I find the file mysqld.service?
How can I find the file mysqld.service?

Time:06-01

I use Ubuntu and I tried to install MySQL and adjust it. I set my password for root user following the instruction 'sudo mysql_secure_installation'. After 'sudo mysql' command I have received this error:

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

I found the answer where I should try this command to check my MySQL server:

systemctl status mysqld.service

But I've got another error:

Unit mysqld.service could not be found.

I don't know how to fix it. I have tried to reinstall the server, but the error occurs again.

CodePudding user response:

Usually nowadays Ubuntu ships with MariaDB. With the output of service mysql status (note that it does miss the "d") you can find from where the package obtains its service file. In the case of MariaDB 10.1.48 on Ubuntu 18.04 it is located in /lib/systemd/system/mariadb.service. Maybe you forgot to start the DBMS? service mysql start would help you out in that case. To autostart MariaDB you may try systemctl enable mysql

EDIT: You may also try replacing mysql with mariadb within the commands above.

CodePudding user response:

3 different Steps to fix this issue

I faced this issue before and solved this by implementing Method 3

Method 1 : Check the MySQL Service

You need to check the mysqld status, if it is inactive then start and enable the service

sudo systemctl status mysqld
sudo systemctl start mysqld
sudo systemctl enable mysqld

Method 2 : Verify mysqld.sock

Find the current mysqld.sock location

sudo find / -type s

The output will show this location,

/run/mysql/mysqld.sock
/run/mysqld/mysqlx.sock

Now open the MySQL configuration

sudo nano /etc/mysql/my.cnf

Add these commands,

[mysqld]
socket=[path to mysqld.sock]
[client]
socket=[path to mysqld.sock]

Create a symlink from the location of mysqld.sock to the /var/run/mysqld directory,

ln -s [path to mysqld.sock] /var/run/mysqld/mysqld.sock

Finally, restart the MySQL service

sudo systemctl restart mysql

Method 3 : Check MySQL folder permission

Check MySQL folder permission,

sudo chmod -R 755 /var/run/mysqld

This permission will allow user to read write and execute the directory.

Now restart the service

sudo systemctl restart mysql

Thanks!!!

  • Related