MySQL: An ERROR 1045 ERROR occurred while creating the user.

Source: Internet
Author: User
Tags mysql manual

When cleaning up unnecessary users after installing MySQL today, I accidentally deleted root @ localhost and added it again. Then I want to add a user to connect to the remote machine, as a result, the user cannot be added.


Mysql> select user ();
+ ---------------- +
| User () |
+ ---------------- +
| Root @ localhost |
+ ---------------- +
1 row in set (0.00 sec)
Mysql> grant select on *. * to baichi @ localhost identified by 'baichi ';
ERROR 1045 (28000): Access denied for user 'new' @ 'localhost' (using password: YES)
At that time, my mind was short-circuited. Why can't I add a user as root?
View MySQL Manual
Error: 1045 SQLSTATE: 28000 (ER_ACCESS_DENIED_ERROR)
Message: deny access to user '% s' @' % s' (use password: % s)
I still don't understand why root doesn't work. As a result, there are a lot of search results about the 1045 error. It seems that it does not matter. Later, I closed MySQL and deleted the data DIRECTORY and re-created the database. It was okay, but the cause of the problem was not found.
Look at other people's posts and add a with grant option when adding users. I think it is because this is not added, so users cannot be created. So I checked the statement for creating root @ localhost:
Mysql> show grants for root @ localhost;
+ --------------------------------------------------------------------- +
| Grants for root @ localhost |
+ --------------------------------------------------------------------- +
| Grant all privileges on *. * TO 'root' @ '2017. 0.0.1 'with grant option |
+ --------------------------------------------------------------------- +
1 row in set (0.00 sec)


I will create two more users, one with or without the with grant option.
Mysql> grant all privileges on *. * to new @ localhost;
Query OK, 0 rows affected (0.00 sec)


Mysql> show grants for new @ localhost;
+ Shards +
| Grants for new @ localhost |
+ Shards +
| Grant all privileges on *. * TO 'new' @ 'localhost' identified by password' * 0479CC8AA5F52BEB2CF57050533F16EDEE15F6A0 '|
+ Shards +
1 row in set (0.00 sec)
Mysql> grant all privileges on *. * to 2new @ localhost with grant option;
Query OK, 0 rows affected (0.00 sec)


Mysql> show grants for 2new @ localhost;
+ --------------------------------------------------------------------- +
| Grants for 2new @ localhost |
+ --------------------------------------------------------------------- +
| Grant all privileges on *. * TO '2new' @ 'localhost' with grant option |
+ --------------------------------------------------------------------- +
1 row in set (0.00 sec)


Use these two users to log in and create the users respectively. The user with the grant option can be created.
Now the problem is found. The original thought that all privileges included the permission to create a user. Therefore, no with grant option was added when root @ localhost was created, resulting in the error 1045 at the beginning.

For more information, see:

MySQL ERROR 1045 (28000): Access denied for user 'root' @ 'localhost'

Solution to the 1045 error during MySQL Installation

MySQL remote connection prompt in Linux: ERROR 1045 (28000)

MySQL 1045 error service cannot find path Solution

Related Article

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.