TLDR
-
Change ownership of directory "/var/lib/mysql" to the respective owner:group,
mysql:mysqlin my case, if MySQL does not start and something like the below pops up in logs[Warning] Can't create file /var/lib/mysql/user.lower-test [ERROR] failed to set datadir to /var/lib/mysql -
Leverage option
skip-grant-tables(with caution, if your machine is connected to the outside world) with MySQL to reset password, if you can not log into MySQL$ echo "skip-grant-tables" | sudo tee -a /etc/mysql/my.cnf $ sudo systemctl restart mysqld.service $ mysql# wanted a no-password login for root user here mysql> UPDATE mysql.user SET authentication_string = null WHERE User = 'root';$ sudo sed -i '/skip-grant-tables/d' /etc/mysql/my.cnf $ sudo systemctl restart mysqld.service
Context
MySQL is installed from package "mysql57" via yay.
Troubleshooting
MySQL Does not Start
-
Good ol'
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)printed on screen when trying to use MySQL CLI with$ sudo mysql -
It showed up dead with exit status 1 in
$ systemctl status mysqld.service -
Found the below in logs with
$ journalctl -u mysqld.service[Warning] Can't create file /var/lib/mysql/user.lower-test [ERROR] failed to set datadir to /var/lib/mysql -
Realized that it could be something about insufficient permission, with some googling
- It said the owner:group is
root:rootin$ ls -al /var/lib | grep mysql - Check the service file (mine was at "/usr/lib/systemd/system/mysqld.service", shown right after "Loaded: loaded" in
$ systemctl status mysqld.service) to see how MySQL was being started - Turned out that it was trying to use
mysql:mysqlas the user:group to start the service
$ sudo chown mysql:mysql- Showed up running after restarting MySQL with
$ sudo systemctl restart mysqld.service
MySQL Does not Start
-
Failed to log in with root user,
$ sudo mysql -
Appended the option
skip-grant-tablesto "/etc/mysql/my.cnf" then restart MySQLExercise this with caution. You might want to append
skip-networkingto the config file as well to cut remote connections# may use "skip-grant-tables\nskip-networking" instead to play safe here $ echo "skip-grant-tables" | sudo tee -a /etc/mysql/my.cnf $ sudo systemctl restart mysqld.service -
Logged into MySQL to remove password
mysql> UPDATE mysql.user SET authentication_string = null WHERE User = 'root'; -
Turned of the option(s) then restart MySQL again
# or use regex '/^skip-grant-tables$\|%skip-networking$/d' $ sudo sed -i '/^skip-grant-tables$/d' /etc/mysql/my.cnf $ sudo systemctl restart mysqld.service -
$ sudo mysqlto log in