MySQL ERROR 1044 (42000): Access denied for user "@ ' localhost ' to database

Source: Internet
Author: User
Tags postgresql create database phpmyadmin
MySQL as a popular open-source database management system is widely used in various scenarios, Alibaba Cloud provides high available ApsaraDB RDS for MySQL with enhanced MySQL service is now supporting businesses fighting Coronavirus COVID-19.



1. Description of the problem:



The following information appears in creating the database under the MySQL console:



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



2. Workaround:



Execute the following command into the console: (under MySQL bin file)



MySQL--user=root-p



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



To create a database:



Create database Python;



Show 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), 2014,oracleand/or its affiliates. All rights reserved.



Oracle is a registered trademark of the Oracle Corporation and/or its
Affiliates. Other names 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>



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



4, Method four:



These days with a blank password login mysql, and then modify the MySQL default password, the use of MySQL table has been the problem, hint: Error 1044 (42000): Access denied for user "@" localhost ' to database ' MySQL '. Find some methods on the net, finally fix.



I use XAMPP integrated MySQL, before the empty password can be logged into the phpMyAdmin, but how can not go to phpmyadmin system table

Later resolved the success of the discovery is because the user table of the MySQL database, the existence of the username is empty account is anonymous account, resulting in the login is the use of root, but the actual anonymous login, through the error prompt "@" localhost can be seen. I solved the problem with a method,

Method One:
In the My.ini [mysqld] field, add:



Skip-grant-tables



Restart the MySQL service when MySQL does not require a password to log in to the database
And then into MySQL.



Mysql>use MySQL;
Mysql>update user Set Password=password (' New password ') WHERE user= ' root ';
Mysql>flush privileges;



After running, finally remove the My.ini in the Skip-grant-tables, restart mysqld can be.

Modify MySQL Password method two:
Do not modify the MySQL password by using the non-service mode plus skip-grant-tables to run MySQL without modifying the My.ini method of restarting the service
Stop MySQL Service
Open a command-line window and start with Mysqld-nt.exe in the bin directory, which is executed at the command-line window: Mysqld-nt--skip-grant-tables
Then open a command-line window, log in to MySQL, no need to enter the MySQL password to enter.
After modifying the password as above, close the command line to run the MySQL window, this time the MySQL is turned off, if you find that MySQL is still running, you can end the process to close off.
Start the MySQL service.



How to handle Linux:







mysql> use mysql
ERROR 1044 (42000): Access denied for user ‘root‘@‘localhost‘ to database ‘mysql‘
mysql> exit
Bye
[[email protected] ~]# service mysqld stop 
Stopping mysqld:                      [ OK ]
[[email protected] ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking & 
 
[[email protected] ~]# 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
[[email protected] ~]# service mysqld start 
 
restart Linux/OS


Reference Blog: https://www.jb51.net/article/72395.htm



MySQL ERROR 1044 (42000): Access denied for user "@ ' localhost ' to database


Alibaba Cloud Hot Products

Elastic Compute Service (ECS) Dedicated Host (DDH) ApsaraDB RDS for MySQL (RDS) ApsaraDB for PolarDB(PolarDB) AnalyticDB for PostgreSQL (ADB for PG)
AnalyticDB for MySQL(ADB for MySQL) Data Transmission Service (DTS) Server Load Balancer (SLB) Global Accelerator (GA) Cloud Enterprise Network (CEN)
Object Storage Service (OSS) Content Delivery Network (CDN) Short Message Service (SMS) Container Service for Kubernetes (ACK) Data Lake Analytics (DLA)

ApsaraDB for Redis (Redis)

ApsaraDB for MongoDB (MongoDB) NAT Gateway VPN Gateway Cloud Firewall
Anti-DDoS Web Application Firewall (WAF) Log Service DataWorks MaxCompute
Elastic MapReduce (EMR) Elasticsearch

Alibaba Cloud Free Trail

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.