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

天大地大妈咪最大 提交于 2019-12-19 03:13:27

问题


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?


回答1:


It means your password is wrong or the account "root" has no access to the database on host "localhost".

Look at the right side bar. There are multiple questions equivalent to yours.




回答2:


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.




回答3:


On Windows -

  1. Search for services
  2. Stop the service named MySQL[#] (in my case it was MySQL80).
  3. Start the service again.
  4. Open Command Prompt and type:

    mysql [database name] -u [user name] -p

It worked for me when no other solutions worked. Hope this solves your issue as well.



来源:https://stackoverflow.com/questions/11957260/mysql-error-1045-28000-access-denied-for-user-rootlocalhost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!