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条回答
淡お忘
2楼-- · 2019-01-03 04:40

BY default password will be null, so you have to change password by doing below steps.

connect to mysql

root# mysql

Use mysql

mysql> update user set password=PASSWORD('root') where User='root'; Finally, reload the privileges:

mysql> flush privileges; mysql> quit

查看更多
放荡不羁爱自由
3楼-- · 2019-01-03 04:44

You have to reset the password! steps for mac osx(tested and working) and ubuntu

Stop MySQL using

sudo service mysql stop

or

$ sudo /usr/local/mysql/support-files/mysql.server stop

Start it in safe mode:

$ sudo mysqld_safe --skip-grant-tables --skip-networking

(above line is the whole command)

This will be an ongoing command until the process is finished so open another shell/terminal window, log in without a password:

$ mysql -u root

mysql> UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';

As per @IberoMedia's comment, for newer versions of MySQL, the field is called authentication_string:

mysql> UPDATE mysql.user SET authentication_string =PASSWORD('password') WHERE User='root';

Start MySQL using:

sudo service mysql start

or

sudo /usr/local/mysql/support-files/mysql.server start

your new password is 'password'.

查看更多
We Are One
4楼-- · 2019-01-03 04:45

The answer may sound silly, but after wasting hours of time, this is how I got it to work

mysql -u root -p

I got the error message

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

Even though I was typing the correct password(the temporary password you get when you first install mysql)

I got it right when I typed in the password when the password prompt was blinking

查看更多
一纸荒年 Trace。
5楼-- · 2019-01-03 04:46

It happens when your password is missing.

Steps to change password when you have forgotten:

  1. Stop MySQL Server (on Linux):

    sudo systemctl stop mysql
    
  2. Start the database without loading the grant tables or enabling networking:

    sudo mysqld_safe --skip-grant-tables --skip-networking &
    

    The ampersand at the end of this command will make this process run in the
    background so you can continue to use your terminal and run #mysql -u root, it will not ask for password.

    If you get error like as below:

    2018-02-12T08:57:39.826071Z mysqld_safe Directory '/var/run/mysqld' for UNIX
    socket file don't exists. mysql -u root ERROR 2002 (HY000): Can't connect to local MySQL server through socket
    '/var/run/mysqld/mysqld.sock' (2) [1]+ Exit 1

  3. Make MySQL service directory.

    sudo mkdir /var/run/mysqld
    

    Give MySQL user permission to write to the service directory.

    sudo chown mysql: /var/run/mysqld
    
  4. Run the same command in step 2 to run mysql in background.

  5. Run mysql -u root you will get mysql console without entering password.

    Run these commands

    FLUSH PRIVILEGES;
    

    For MySQL 5.7.6 and newer

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

    For MySQL 5.7.5 and older

    SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');
    

    If the ALTER USER command doesn't work use:

    UPDATE mysql.user SET authentication_string = PASSWORD('new_password')     WHERE User = 'root' AND Host = 'localhost';
    

Now exit

  1. To stop instance started manually

    sudo kill `cat /var/run/mysqld/mysqld.pid`
    
  2. Restart mysql

    sudo systemctl start mysql
    
查看更多
Animai°情兽
6楼-- · 2019-01-03 04:46

Just one line and it solved my issue.

sudo dpkg-reconfigure mysql-server-5.5
查看更多
做自己的国王
7楼-- · 2019-01-03 04:47

if the problem still exists try to force changing the pass

/etc/init.d/mysql stop

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:

/etc/init.d/mysql stop

Start MySQL server and test it:

mysql -u root -p
查看更多
登录 后发表回答