13

I just logged in to Ubuntu 12.04 as a normal user (vivek) and opened the terminal to create a database, I wrote:

create database Hello;

and the error I had is:

ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'vivek'

If I login as root user then even MySQL is not opening and having the error message:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

What to do now.

Parto
  • 15,325
  • 24
  • 86
  • 117

2 Answers2

18

To login into MySQL as root user, you can use:

mysql -u root -p

and then enter your MySQL password.


To login as another user, you will have to create that user first and grant him privileges.

Create the user using - change newuser to the username you want and password to your password of choice.

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

Sadly, at this point newuser has no permissions to do anything with the databases.
Therefore the first stage is to grant the user the privileges to do 'things'.
To grant all privileges (select, create, delete, update, drop, etc) on all databases and tables, run:

GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';

To grant a specific privilege on a particular database and table, just run:

GRANT [type of privilege] ON [database name].[table name] TO '[username]'@'localhost';

If you ever need to deny or revoke a certain privilege, just run:

REVOKE [type of permission] ON [database name].[table name] FROM '[username]'@'localhost';

Source: https://www.digitalocean.com/community/articles/how-to-create-a-new-user-and-grant-permissions-in-mysql

Parto
  • 15,325
  • 24
  • 86
  • 117
1

open the mysql in save mode

sudo mysqld_safe --skip-grant-tables

===============================

login mysql as root user

mysql -u root

===============================

grant all PRIVILEGES for that a/c

GRANT ALL PRIVILEGES ON `%`.* TO 'root'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

i think this will also work ...

Sudip Das
  • 300