Linux mysql error 1045

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

I have been following a manual to install a software suite on Ubuntu. I have no knowledge of MySQL at all. 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 
cd ~/Desktop/iPDC-v1.3.1/DBServer-1.1 mysql -uroot -proot  

Future visitors, also don't forget to check the several causes explained here: dev.mysql.com/doc/refman/8.0/en/problems-connecting.html

40 Answers 40

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

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

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 database as well.

@FarticlePilter The -p flag specifies the password, so after you change your root password you would do like mysql -u root -p[newpassword] . The < [filename] is using std input to execute an SQL file at the path given via the user credential you provide.

I tried as told mysqladmin -u root password abc1234 , but I got mysqladmin: connect to server at 'localhost' failed error: 'Access denied for user 'root'@'localhost' (using password: NO)' . Thank you so much!

@Kanagaroo in this question, the OP states they just installed MySQL for the first time and then tried to access via MySQL command line client. That sounds like first time access to me.

Actually for mysql community server 5.7, the default root password is randomly generated when you install. Check your /var/log/mysqld.log for a line talking about a "temporary password". Saves hours of messing around.

@BraianMellor This does solve the problem for MySQL < 5.7 in that the default (post-installation) root password on Ubuntu is blank (no password), where in the original question the poster was trying to use root/root. The question was not about lost password, changing password, or similar. For newer versions of MySQL the other answer I referenced is the correct one, as a user must look in the error logs to see the randomly-generated root password.

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:

After which it asks you for a password like this

And then I typed in the password I used. That's all.

I was able to solve this problem by executing this statement

sudo dpkg-reconfigure mysql-server-5.5 

Which will change the root password.

Just what I needed. but not everyone has version 5.5 of server. use dpkg --get-selections | grep sql to get your version

When I run this command in Mac OS X, I get this error: sudo: dpkg-reconfigure: command not found . Any suggestion?

You have to reset the password! Steps for Mac OS X (tested and working) and Ubuntu:

sudo /usr/local/mysql/support-files/mysql.server stop 
sudo mysqld_safe --skip-grant-tables --skip-networking 

(the 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"; 
sudo /usr/local/mysql/support-files/mysql.server start 

Your new password is 'password'.

Note: for version of MySQL > 5.7 try this:

update mysql.user set authentication_string="password" where user="root"; 

Please, NOT that way ! @Divz's answer is more secure. Quoting the doc about --skip-grant-tables : This enables anyone to connect without a password and with all privileges [. ] Because this is insecure, [. ] use --skip-grant-tables in conjunction with --skip-networking to prevent remote clients from connecting. oh, and also, this one didn't work for me. Thats why I came here :p

If you go that way, yes. It didn't work for me, and following @Divz's answer seems way easier to me, anyway -- What I would suggest is using dpkg --get-selections | grep mysql-server- to get your exact MySQL version, then go for sudo dpkg-reconfigure mysql-server-5.x (replace 5.x with your server version, btw). I commented @Divz's answer with this precision, but it's masked by the several "thanks" comments.

I've to change the command sudo mysql restart for sudo service mysql restart , and it worked like a charm.'I've edited your post.

Since MySQL 5.7.6 the Password column was renamed "authentication_string" Here you can read more about it: bugs.mysql.com/bug.php?id=76655

It happens when your password is missing.

Steps to change the password when you have forgotten it:

    Stop MySQL Server (on Linux):

sudo systemctl stop mysql 
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 (as root). It will not ask for a 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 
sudo chown mysql: /var/run/mysqld 
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password'; 
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password'); 
UPDATE mysql.user SET authentication_string = PASSWORD('new_password') WHERE User = 'root' AND Host = 'localhost'; 
sudo kill `cat /var/run/mysqld/mysqld.pid` 
sudo systemctl start mysql 

This is the one that worked for me. In step 5, do 1. use USER 2. To change password use --> update user set authentication_string = PASSWORD("password") where User='root';

This is the best solution, I could find out. Using "5.7.26 MySQL Community Server (GPL)" on macOS Mojave on a MBP '15 model. I had to stop Mysql from System Preference, and then followed step 2 and step 5. And then I had to kill the MySQL process by looking up the PID using ps -ef | grep mysql.

After hours and days of hitting my head on this and too lazy to find cause of error in step 2. Thank you so much for this answer. Finally I can see mysql -u root -p working with my new password

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 -u root -p mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass5!'; 

This looked promising, but it doesn't work for me. When I run sudo grep 'temporary password' /var/log/mysqld.log I get /var/log/mysqld.log: No such file or directory

Try shell> sudo grep 'password' /var/log/mysql/error.log . Worked for me, but I get: root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option. My mysql version is: Ver 8.0.13 for Linux on x86_64 (MySQL Community Server - GPL)

@EnginYilmaz why do you suggest a mysql command when the problem is that mysql is not even accessible?

If the problem still exists, try to force changing the password:

/etc/init.d/mysql stop mysqld_safe --skip-grant-tables & mysql -u root 

Set up a new MySQL root user password:

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

Start the MySQL server and test it:

Thank you. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) was also plaguing my server. 'mysqld_safe' also failed until I did a 'killall mysqld' AFTER your Step 1.

Please, NOT that way ! @Divz's answer is more secure. Quoting the doc about --skip-grant-tables: This enables anyone to connect without a password and with all privileges [. ] Because this is insecure, [. ] use --skip-grant-tables in conjunction with --skip-networking to prevent remote clients from connecting. oh, and also, this one didn't work for me. Thats why I came here :p

@MD.MohiuddinAhmed You must be using newer version of mysql-server. Refer this answer : stackoverflow.com/a/31122246/6242649

If none of the other answers work for you, and you received this error:

mysqld_safe Logging to '/var/log/mysql/error.log'. mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists. [1]+ Exit 1 sudo mysqld_safe --skip-grant-tables 

Follow the below commands step by step until you reset your password:

# Stop your server first sudo service mysql stop # Make the MySQL service directory. sudo mkdir /var/run/mysqld # Give MySQL permission to work with the created directory sudo chown mysql: /var/run/mysqld # Start MySQL, without permission and network checking sudo mysqld_safe --skip-grant-tables --skip-networking & # Log in to your server without any password. mysql -u root mysql # Update the password for the root user: UPDATE mysql.user SET authentication_string=PASSWORD('YourNewPasswordBuddy'), plugin='mysql_native_password' WHERE User='root' AND Host='localhost'; # If you omit (AND Host='localhost') section, it updates # the root password regardless of its host FLUSH PRIVILEGES; EXIT; # Kill the mysqld_safe process sudo service mysql restart # Now you can use your new password to log in to your server mysql -u root -p # Take note for remote access. You should create a remote # user and then grant all privileges to that remote user 

Источник

error 1045 (28000) access denied for user 'root'@'localhost' (using password: YES)

Please forgive me for being a complete beginner: I am trying to log into my very first mySQL database that I installed using easyPHP on my windows machine, using the cmd line. I am going to the \mysql\bin and entering the command:

error 1045 (28000) access denied for user 'root'@'localhost' (using password: YES) 

Why is it using the password "YES"? Shouldn't there be no password at all? Do I need to restart mySQL or something? If so, how do I do that? If it's relevant, I did try to create the database using phpmyadmin, but had a few problems entering columns and decided I'd be better off working from the command line so I could learn all the commands as I went along. Please keep in mind that this is my first time ever trying to work with a database, so be kind to me!

4 Answers 4

To have mysql asking you for a password, you also need to specify the -p -option:

That worked, thanks. Is there somewhere I can learn more about the various commands and things I need to use terminals? Are they significantly different for Windows and Linux?

No, the commands aren't different for the mysql command line client on Windows or Linux. But they can differ from version to version (of mysql ). I think you should read the manual: dev.mysql.com/doc/refman/5.5/en/mysql.html On Linux you can also use man mysql to get a quick overview.

Just a note for Mac users that if you change your root password, this login command uses whatever password you set within mysql, not your Mac's root password.

When logging into MYSQL using the command line, you also have to specify the password if any. Your error message is telling you that the user "root" has a password attached to it. Not necessarily that the password is "YES" when you were installing easyPHP, it should have either provided you with a default password or allowed you to enter a password of your choosing.

According to the documentation of easyPHP:

[v1.6] My scripts worked perfectly with 1.5 but now I get this error : Warning: Forbidden access for user: 'user@localhost' (password: YES) when I want to connect to MySql.

Only the root user (without password) has the rights to connect to the database. Either modify your scripts to use it, or add the user you need (phpMyAdmin/users and privileges: See phpMyAdmin's documentation for more information).

Now if you changed your root user password, you will need to specify that when prompted. Otherwise simply hit on your keyboard.

If you FORGOT the password to root, and have changed it, you will have to subsequently reinstall easyPHP.

Источник

Читайте также:  Linux подключить два компьютера
Оцените статью
Adblock
detector