jas0nhuang

MySQL Errors on Linux

1. Error when try to start MySQL client

mysql -u USERNAME -p
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

This error might be caused by no running mysql server.
Try to restart the mysql server.

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

As it says, no access right. But may have different reasons.

2. Error when try to start the server

systemctl start mysqld.server

got some error:

job for mysql.service failed because the control process exited with error code

or maybe:

Unit mysqld.service not found

It sometimes stuck during the startup process.

For all the errors above, I think they are all caused by some mysql and mariadb conflicts(not sure). I did not find any way to solve them, so I just reinstall the whole linux system. And install only MySQL. Everything work just fine afterwards.

It might also solve these problems by uninstalling and reinstall MySQL/Mariadb. Probably need to clean up all residule files left in the system.

3. Error try to install mysqlclient for python

pip3 install mysqlclient

And I got this error…

raise EnvironmentError("%s not found" % (_mysql_config_path,))
OSError: mysql_config not found
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-f0a69vku/mysqlclient/

Seems that I need to install a devel environment.

So:

dnf install mysql-devel

Retry install with pip3 install mysqlclient.And still error:

unable to execute 'gcc': No such file or directory
error: command 'gcc' failed with exit status 1

No gcc, install it:

dnf install gcc

And still error:

MySQLdb/_mysql.c:37:10: fatal error: Python.h: No such file or directory
#include "Python.h"
^~~~~~~~~~
compilation terminated.
error: command 'gcc' failed with exit status 1

Well, also need python devel. So do this:

dnf install python3-devel

And I can finally install mysqlclient on python.

4. Error when try to create a databaese:

(Added on 2019-11-17)
If you got this error when creating database:

ERROR 1044 (42000): Access denied for user 'USERNAME'localhost' to database ''

It’s probably because no privilege was granted to this user. Do the following under root account:

GRANT ALL PRIVILEGES ON * . * TO 'USERNAME'@'localhost';

The meaning of this line:

GRANT [type of privilege] ON [database name].[table name] TO '[username]'@'localhost';

and use REVOKEFROM to revoke privileges from an user.