Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MYSQL error: 1045 (28000): Access denied for user 'root'@'localhost'

When I try to connect to the sql server and enter the following in command prompt:

shell> mysql --user=username--password=password db_name

I get error:

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

What does this error mean?

like image 960
Maria Avatar asked Nov 13 '22 00:11

Maria


1 Answers

Looks like a space is missing between username and --password


If you don't know the root password, with Debian or Ubuntu, there is an easy way to reset it : First, get the exact version of your server using

sudo dpkg --get-selections | grep 'mysql-server-'

Then, just use sudo dpkg-reconfigure mysql-server-5.x

(btw, replace 5.x with you real version number)


On a fresh install, the default root password is blank, so should be able to log in using just

mysql -u root

You should obviously add a root password after installation

mysqladmin -u root password [newpassword]

In most cases, you should also set up dedicated accounts with limited rights before working with a DB.

like image 66
Balmipour Avatar answered Dec 06 '22 11:12

Balmipour