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

Source: Internet
Author: User
Tags anonymous flush create database phpmyadmin

1. Question Description:

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

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

2. Solution:

Execute the following command into the console:

MySQL--user=root-p

Enter the root user's password 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 the Oracle Corporation and/or its
Affiliates. Names may 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, using the MySQL table has been the problem, prompted: Error 1044 (42000): Access denied for user ' @ ' localhost ' to database ' MySQL '. I found some methods on the Internet and finally got it done.

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

Later resolved the successful discovery is because of the MySQL database user table, there is an anonymous account that is named empty account, resulting in the login is although the use of root, but is actually anonymous login, through the error prompted in the ' @ ' 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 need a password to log on 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 the operation finally remove the My.ini in the Skip-grant-tables, restart the mysqld can be.

To Modify the MySQL password method two:
Do not use modify My.ini Restart service method, through the non-service mode plus skip-grant-tables run MySQL to modify the MySQL password
Stop MySQL Service
Open a Command line window and start with Mysqld-nt.exe in the bin directory, which is done at the Command Line window: Mysqld-nt--skip-grant-tables
Then open a different command line window, login MySQL, no need to enter the MySQL password to enter.
After modifying the password, close the command line to run the MySQL window, then shut down MySQL, if found that MySQL is still in operation can end the corresponding process to close.
Start the MySQL service.

The processing method under Linux:

mysql> use MySQL
ERROR 1044 (42000): Access denied for user ' root ' @ ' localhost ' to database ' MySQL '
mysql> ex It
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 

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.