6

This question seem to be asked a lot however I cannot find a definitive answer.

I am making some webapp tests using MySQL, and at the beginning I used the 'root' user (with a non-empty password). My root user is working fine from the apps (tested from PHP and Python's Django), from the command line, and with PHPMyAdmin.

However I don't wanted to use the the root user, so I created another user, and I granted all privileges to the databases that user should need. (I used PHPMyAdmin logged as 'root' for this task).

The new user cannot log in to MySQL. Neither from the Django app, nor PHPMyAdmin, nor the command line.

I have two possible suspicions:

  1. there is a global privilege the user lacks. (As I said, I granted all database privileges, however I have not granted any global privileges);

  2. the user's configured host. ('root' has four lines in the mysql.user table, for hosts 'localhost', 'my-pc-name', '127.0.0.1' and '::1'; while the new user has one line for host '%')

(I have double-checked the password, so I am confident this is not a password problem.)

5
  • 1
    show how u create a new user in mysql Commented Apr 13, 2013 at 14:50
  • Did you try granting privileges specifically for user@localhostinstead of using % wildcard? Commented Apr 13, 2013 at 14:59
  • @Tamil: I created the new user with PHPMyAdmin. Commented Apr 13, 2013 at 15:03
  • @Uby: I finally did it and it worked. Commented Apr 13, 2013 at 15:04
  • 1
    @CarlosEugenioThompsonPinzón Good, keep in mind that % would not match unix socket connections, so you need to explicitly grant privileges for localhost Commented Apr 13, 2013 at 15:06

2 Answers 2

5

% means that the new user can access the database from any host.

However, if you supplied the CREATE USER statement would be much more useful.

In addition, check MySQL Manual below, where it explains why a user should have both @'localhost' and @'%':

MySQL Reference Manual - Adding Users

Sign up to request clarification or add additional context in comments.

2 Comments

Adding the user as @'localhost' helped. Thank you.
It's a shame that if it's so important to have a localhost version of each user that by default mysql's own admin program ("mysql workbench ce") doesn't provide an option for doing so in its modelling mode, instead providing only a way of creating the "@%" variant.
0

restarting mysql server + "flush privileges;" command solved it for me

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.