When using the root user to access the database locally, the mysql library is not displayed?
And create a database error
MariaDB [(none)]> create database mysql;
ERROR 1044 (42000): Access denied for user ‘’@‘localhost’ to database ‘mysql’
1. Problem background
- When using the root user to access the database normally as follows
You can see some system information of the mysql library
- The error is as follows
- For example, I create a database permission error
2. Solutions
Tried many methods, even reinstalling mysql found that it still failed, and encountered another problem: mysql uninstallation is not clean
How to uninstall mysql completely and cleanly, please refer to: https://blog.csdn.net/m0_49562857/article/details/129049754?spm=1001.2014.3001.5502
Later, I searched a lot of information and found that it was not the mysql library that was deleted, but all the root users and all related authorizations of the root users were deleted, which caused me to report an error when using the root user to access the database.
Solution:
- close database
systemctl stop mariadb
- Shield permission to start the database
mysqld_safe --skip-grant-table
-
Start another linux window
- 1. Enter the database
mysql -uroot mysql
- 2. Query all users and their authorization status in the current database
select host,user,password from mysql.user;
If you have a root user, please refer to step 4
For non-root users, please refer to step 5
- 3. Delete users with empty passwords
delete from user where USER=''; FLUSH PRIVILEGES;
- 4. After querying, it is found that there is a root user in the system to execute the following command
UPDATE user SET Password=PASSWORD('新密码') where USER='root'; FLUSH PRIVILEGES;
- 5. After querying, it is found that there is no root user in the system to execute the following command
grant all on *.* to 'root'@'localhost' identified by '新密码'; flush privileges;
-
kill the existing mysql process
- Start the database query and find that the mysql library is displayed