mysql ERROR 1044 of 42000 : Access denied for user ''@'localhost' to database

  • 2020-11-18 06:30:25
  • OfStack

1. Problem Description:

The following information appears when creating a database under the MySQL console:

mysql > CREATE DATABASE python;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'python'

2. Solutions:

Execute the following command to enter the console:

mysql --user=root -p

Enter the password of root user to enter the mysql console:

Create database:

create database python;

Display all databases:

show databases;

As follows:

www.linuxidc.com @www.linuxidc.com:~$ mysql --user=root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2014,Oracleand/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql > create database python;
Query OK, 1 row affected (0.00 sec)

mysql > show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| python |
| test |
+--------------------+
5 rows in set (0.02 sec)

mysql >

OK, the above method is not the best, but is simple and feasible, Enjoy it!!

4. Method 4:

ERROR 1044 (42000): denied for '@'localhost' database 'mysql' I found some methods on the Internet and finally got it done.

I used xampp integrated mysql, before empty password can be logged in phpmyadmin, but how can not enter the phpmyadmin system table

Later, it was found that the solution was successfully solved because in the mysql database table, there was an account with empty user name, that is, an anonymous account. As a result, although root was used when logging in, it was actually an anonymous login, which could be seen from the error prompt of '@'localhost'. I solved the problem with method one,

Method 1:
Add the [mysqld] field of ES130en. ini:

skip-grant-tables

Restart the mysql service so that mysql does not need a password to log in to the database
Then enter mysql

mysql > use mysql;
mysql > update user set =password(' new password ') WHERE User='root';
mysql > flush privileges;

After running my. ini skip-ES167en-ES168en, restart mysqld.

Change mysql password method 2:
Instead of using the method of modifying my.ini to restart the service, run mysql with ES176en-ES177en-ES178en in a non-service manner to modify the mysql password
Discontinue mysql service
Open the command line window and start using es185EN-ES186en.exe in the bin directory. That is, execute the command line window: ES188en-ES189en -- skip-ES191en-ES192en
Then open another command line window and log in to mysql without entering the mysql password.
After modifying the password in the above method, close the window where mysql is running on the command line. At this time, mysql is closed. If it is found that mysql is still running, the corresponding process can be terminated to close it.
Start the mysql service.

Treatment method under linux:


mysql> use mysql
ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'mysql'
mysql> exit
Bye
[root@testtest ~]# service mysqld stop 
Stopping mysqld:                      [ OK ]
[root@testtest ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking & 

[root@testtest ~]# mysql -u root -p -hlocalhost
Enter password: 

mysql> use mysql

mysql> SELECT host,user,password,Grant_priv,Super_priv FROM mysql.user;

mysql> UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y' WHERE User='root';

mysql> FLUSH PRIVILEGES;

mysql> GRANT ALL ON *.* TO 'root'@'localhost';

mysql> GRANT ALL ON *.* TO 'root'@'cn.cn.cn.cn';

mysql> GRANT ALL ON *.* TO 'root'@'245.245.245.245';

mysql> GRANT ALL ON *.* TO 'root'@'127.0.0.1';

mysql> FLUSH PRIVILEGES;


mysql> quit
Bye
[root@testtest ~]# service mysqld start 

restart Linux/OS 


Related articles: