I'm trying to reset my mariadb password following this site -> https://www.rosehosting.com/blog/how-to-reset-your-mariadb-root-password/
but when I enter mysql -u root I get the following error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")

Any ideas? Thanks.

Dani AI

Generated

Short answer: that symptom means the client cannot find the server's UNIX socket — usually because the MariaDB server isn't running, it failed to start, or the server is configured to use a different socket path. 's suggestion to check whether the service was stopped is on point, and since confirms it was, run a few quick checks to see why the server isn't listening.

Check whether the server process and service are running:

sudo systemctl status mariadb
# or, on some systems:
sudo systemctl status mysql
sudo service mysql status

ps aux | grep -E 'mariadbd|mysqld'

If the service is stopped, try starting it and inspect recent logs for startup errors (permission problems, AppArmor/SELinux denials, wrong datadir, etc.):

sudo systemctl start mariadb
sudo journalctl -u mariadb -n 200 --no-pager
sudo tail -n 200 /var/log/mysql/error.log

If the goal is to reset the root password and the normal start fails, use a safe emergency start, change the password, then restart normally. Start the server without grant tables (use --skip-networking to avoid exposing it), perform the password change inside the server, flush privileges, and then restart:

sudo systemctl stop mariadb
sudo mysqld_safe --skip-grant-tables --skip-networking &
# inside the SQL client run:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewStrongPassword';
FLUSH PRIVILEGES;
sudo systemctl restart mariadb

Other quick gotchas: verify the socket directory exists and is owned by the mysql user (create and chown it if missing), and check alternate socket locations in your my.cnf files if the client and server disagree. If startup still fails, paste the last 50–200 lines of the MariaDB error log or the output of the journalctl command so the failure reason can be diagnosed.

Recommended Answers

All 2 Replies

I won't pretend that I know what I'm talking about, but did you shut down the MySQL service first as in the instructions?

Indeed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.