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:30

Am using Ubuntu-16.04 : installed mysql - 5.7. I Had the same issue : Login denied for root user.

Tried the below steps:

1. dpkg --get-selections | grep mysql (to get the version of mysql).

2. dpkg-reconfigure mysql-server-5.7

3. mysql -u root -p

Without -p that doesn't prompt you to ask password. Once you are in, you can create a user with a password by following steps :

CREATE USER 'your_new_username'@'your-hostname' IDENTIFIED BY 'your-password';

GRANT ALL PRIVILEGES ON *.* to 'your_new_username'@'your-hostname' WITH GRANT OPTION;

Exit from the root and login from the you gave above.

mysql -u <your_new_username> -p

For some reason still just typing mysql does not work. AT ALL. I suggest to make it a habit to use mysql -u -p.

查看更多
趁早两清
3楼-- · 2019-01-03 04:30

In Ubuntu 16.04 (MySQL version 5.7.13) I was able to resolve the problem with the steps below:

  1. Follow the instructions from the in section B.5.3.2.2 Resetting the Root Password: Unix and Unix-Like Systems MySQL 5.7 reference manual

  2. When I tried #sudo mysqld_safe --init-file=/home/me/mysql-init & it failed. The error was in /var/log/mysql/error.log

    2016-08-10T11:41:20.421946Z 0 [Note] Execution of init_file '/home/me/mysql/mysql-init' started. 2016-08-10T11:41:20.422070Z 0 [ERROR] /usr/sbin/mysqld: File '/home/me/mysql/mysql-init' not found (Errcode: 13 - Permission denied) 2016-08-10T11:41:20.422096Z 0 [ERROR] Aborting

The file permission of mysql-init was not the problem, need to edit apparmor permission

  1. Edit by #sudo vi /etc/apparmor.d/usr.sbin.mysqld

    ....
      /var/log/mysql/ r,
      /var/log/mysql/** rw,
    
    
    # Allow user init file
      /home/pranab/mysql/* r,
    
      # Site-specific additions and overrides. See local/README for details.
      #include <local/usr.sbin.mysqld>
    }
    
  2. Do #sudo /etc/init.d/apparmor reload

  3. Start mysqld_safe again try step 2 above. Check /var/log/mysql/error.log make sure there is no error and the mysqld is successfully started

  4. Run #mysql -u root -p

    Enter password:

Enter the password that you specified in mysql-init. You should be able to log in as root now.

  1. Shutdown mysqld_safe by #sudo mysqladmin -u root -p shutdown

  2. Start mysqld normal way by #sudo systemctl start mysql

查看更多
Lonely孤独者°
4楼-- · 2019-01-03 04:33

Please read the official documentation: Mysql: How to Reset the Root Password

If you have access to terminal:

MySQL 5.7.6 and later:

$ mysql
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

MySQL 5.7.5 and earlier:

$ mysql
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
查看更多
唯我独甜
5楼-- · 2019-01-03 04:35

At the initial start up of the server the following happens, given that the data directory of the server is empty:

  • The server is initialized.
  • SSL certificate and key files are generated in the data directory.
  • The validate_password plugin is installed and enabled.
  • The superuser account 'root'@'localhost' is created. The password for the superuser is set and stored in the error log file.

To reveal it, use the following command:

shell> sudo grep 'temporary password' /var/log/mysqld.log

Change the root password as soon as possible by logging in with the generated temporary password and set a custom password for the superuser account:

shell> mysql -uroot -p 

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass5!'; 
查看更多
劳资没心,怎么记你
6楼-- · 2019-01-03 04:35

I know this an old Question but i feel this might help someone. I was recently faced with the same problem but in my case, i remember my password quite alright but it kept on giving me the same error. I tried so many solutions but still none helped then i tried this

mysql -u root -p 

after which it asks you for a pass word like this

Enter password: 

and then i typed in the password i used. That's all

查看更多
该账号已被封号
7楼-- · 2019-01-03 04:38

I am using mysql-5.7.12-osx10.11-x86_64.dmg in Mac OSX

The installation process automatically sets up a temporary password for root user. You should save the password. The password can not be recovered.

Follow the instruction

  1. Go to cd /usr/local/mysql/bin/
  2. Enter the temporary password (which would look something like, "tsO07JF1=>3")
  3. You should get mysql> prompt.
  4. Run, SET PASSWORD FOR 'root'@'localhost' = PASSWORD('{YOUR_PASSWORD}'); If you wish to set your password: "root" then the command would be, SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root');
  5. Run ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
  6. Run exit
  7. Run ./mysql -u root -p
  8. Type your password. In my case I would type, "root" (without quote)
  9. That's all.

For convenience, you should add "/usr/local/mysql/bin" to your PATH

Now from anywhere you can type ./mysql -u root -p and then type the password and you will get mysql> prompt.

Hope it helps.

查看更多
登录 后发表回答