0

When I try to create a database I get an error Access denied for user '@'localhost to database emp

When I query show grants

mysql> show grants;
+--------------------------------------+
| Grants for @localhost                |
+--------------------------------------+
| GRANT USAGE ON *.* TO ''@'localhost' |
+--------------------------------------+
1 row in set (0.00 sec)

I'm not able to access as user root.

There is no username that I found.

Also when I am trying to create new user get error as

mysql> create user 'user1'@'localhost';
ERROR 1227 (42000): Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation

How do I create new user and database.

1 Answers1

0

strange that nobody answered.

Here are two links: http://mysqlpreacher.com/wordpress/2011/03/recovering-a-mysql-root-password-three-solutions/ http://iwtf.net/2010/01/05/recovering-a-lost-mysql-root-password/

Basically you need --skip-grant-tables. Pasting from one of the sites:

The solution
This was actually pretty simple. Its just a case of restarting mysql without the authentication tables loaded

sudo /etc/init.d/mysql stop
sudo mysqld_safe --skip-grant-tables &

This stops MySQL and reloads it without the authentication (aka grant) tables, meaning we can connect to MySQL without a password. Beware this locks out all of your customers and applications until the password reset process is completed. Now we need to go in an reset the password

sudo su - 
mysql -u root -p

It will prompt you for a password, just hit enter.

Now create the users you want. with something like:

grant all privileges on *.* to 'root'@'%' identified by 'password' with grant option
grant all privileges on *.* to 'root'@'localhost' identified by 'password' with grant option

Finally restart mysql in the normal way without the --skip-grant-tables option. For granting normal users privileges to some databases, see this answer: https://stackoverflow.com/a/15707789/520567

Creating normal user with the above command is insecure. Only for root you create them like that.

Community
  • 1
  • 1
akostadinov
  • 17,364
  • 6
  • 77
  • 85