ERROR 1045 (28000): Access denied for user 'ro

2019-01-03 04:13发布

I am an electrical engineering who mainly play around with power system instead of programming. Recently, I have been following a manual to install a software suite on Ubuntu. I have no knowledge on mySQL at all, actually. I have done the following installations on my Ubuntu.

sudo apt-get update
sudo apt-get install mysql-server-5.5
sudo apt-get install mysql-client-5.5
sudo apt-get install mysql-common
sudo apt-get install glade
sudo apt-get install ntp

Then I do

me@ubuntu:~/Desktop/iPDC-v1.3.1/DBServer-1.1$ mysql -uroot -proot <"Db.sql"

I ended up with the following error message.

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

How may I fix it and continue?

18条回答
Summer. ? 凉城
2楼-- · 2019-01-03 04:20

Note: For MySQL 5.7+ please see answer from @Lahiru to this question. That contains more current information.

For MySQL < 5.7:

The default root password is blank (i.e. empty string) not root. So you can just login as:

mysql -u root

You should obviously change your root password after installation

mysqladmin -u root password [newpassword]

In most cases you should also set up individual user accounts before working extensively with the DB as well.

查看更多
Luminary・发光体
3楼-- · 2019-01-03 04:20

I was able to solve this problem by executing this statement

sudo dpkg-reconfigure mysql-server-5.5

Which will change the root password.

查看更多
可以哭但决不认输i
4楼-- · 2019-01-03 04:24

I came across this very annoying problem and found many answers that did not work. The best solution I came across was to completely uninstall mysql and re-install it. On re-install you set a root password and this fixed the problem.

sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-core-5.5 mysql-client-core-5.5 sudo rm -rf /etc/mysql /var/lib/mysql sudo apt-get autoremove sudo apt-get autoclean

I found this code elsewhere so I take no credit for it. But it works. To install mysql after uninstalling it I think digital ocean has a good tutorial on it. Checkout my gist for this.
https://gist.github.com/JamesDaniel/c02ef210c17c1dec82fc973cac484096

查看更多
可以哭但决不认输i
5楼-- · 2019-01-03 04:24

if the problem still exists try to force changing the pass

Stop MySQL Server (on Linux):

/etc/init.d/mysql stop

Stop MySQL Server (on Mac OS X):

mysql.server stop

Start mysqld_safe daemon with --skip-grant-tables

mysqld_safe --skip-grant-tables &
mysql -u root

Setup new MySQL root user password

use mysql;
update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
flush privileges;
quit;

Stop MySQL Server (on Linux):

/etc/init.d/mysql stop

Stop MySQL Server (on Mac OS X):

mysql.server stop

Start MySQL server service and test to login by root:

mysql -u root -p
查看更多
该账号已被封号
6楼-- · 2019-01-03 04:27

In recent MySQL versions there is no password in mysql.user table.

So you need to execute ALTER USER. Put this one line command into the file.

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

And execute it as init file (as root or mysql user)

mysqld_safe --init-file=/home/me/mysql-init &

MySQL server need to be stopped to start mysqld_safe.

Also, there may be a problem with apparmor permissions to load this init file. Read more here https://blogs.oracle.com/jsmyth/entry/apparmor_and_mysql

查看更多
ゆ 、 Hurt°
7楼-- · 2019-01-03 04:28

If you haven't set password yet, then run mysql -uroot, it works for me.

查看更多
登录 后发表回答