MysqlERROR1044 (42000): accessdeniedforuser'' @ 'localho _ MySQL

Source: Internet
Author: User
This article mainly introduces the mysql prompt ERROR1044 (42000): Accessdeniedforuser 1. problem description:

The following information is displayed when you create a database on the MySQL console:

Mysql> create database python;
ERROR 1044 (42000): Access denied for user ''@ 'localhost' to database 'Python'

2. solution:

Run the following command to go to the console:

Mysql -- user = root-p

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

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) 2000,201 4, 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>

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

4. Method 4:

After logging on to mysql with an empty password in the past few days, modify the default mysql password. the following ERROR occurs when you use the mysql table: ERROR 1044 (42000 ): access denied for user'' @ 'localhost' to database 'mysql '. I found some methods on the Internet and finally got it done.

I am using mysql integrated with xampp. I can log on to phpmyadmin with a blank password, but I cannot enter the phpmyadmin system table.

Later, it was found that the username table in the mysql database contains an account with an empty username, namely an anonymous account. as a result, the root account is used for logon, but the logon is actually anonymous, you can see the '@ 'localhost' in the error message. I used Method 1 to solve the problem,

Method 1:
Add the following to the [mysqld] field of my. ini:

Skip-grant-tables

Restart the mysql service. mysql can log on to the database without a password.
Then go to mysql

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

After running the command, remove skip-grant-tables from my. ini and restart mysqld.

Method 2:
Without modifying my. ini to restart the service, add skip-grant-tables in non-service mode to run mysql to change the mysql password.
Stop mysql service
Open the command line window and start it with mysqld-nt.exe in the bindirectory. that is, run mysqld-nt -- skip-grant-tables in the command line window.
Open a command line window and log on to mysql. you do not need to enter the mysql password.
After changing the password, close the window in which the command line runs mysql. in this case, mysql is closed. if mysql is still running, stop the corresponding process.
Start the mysql service.

Solution in linux:

mysql> use mysqlERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'mysql'mysql> exitBye[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 -hlocalhostEnter password: mysql> use mysqlmysql> 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> quitBye[root@testtest ~]# service mysqld start restart Linux/OS 

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.