Access denied for user 'root#localhost' (using password: YES) - mysql

When install MySQL in Cent OS, it is installed correctly.
After installation,I type this command in terminal.
/etc/init.d/mysqld start
It shown error and I typed password as 'new-password'. In this time, I found this error.
[root#datsvr018 bin]# /etc/init.d/mysqld start
Starting mysqld: [ OK ]
[root#datsvr018 bin]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current password
for the root user. If you've just installed MySQL, and you haven't set
the root password yet, the password will be blank, so you should just press enter here.
Enter current password for root (enter for none):
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)

Right after install MySQL, you need to run mysqladmin to set root password.
mysqladmin -u root password NEWPASSWORD

Related

Access denied for user 'root'#'localhost' (using password: NO) - what's wrong?

(Sorry for my English)
This is a log of my console:
anton#anton-X451CA:~$ mysql -u root
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
anton#anton-X451CA:~$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
What should I do? I understand that it appears when I try entering without a password, but I am dont confirmed password, and 'root'/empty string doesn't help.
I solved the problem, when:
Change the file my.cnf (in my Ubuntu-system he is placed at /etc/mysql/my.cnf). In the end i added that code:
[mysqld]
skip-grant-tables
That's helps enter in condole as anyone user without pass. Restart the server:
sudo service mysql restart
Enter in the mysql-console:
mysql -u root
Change the password for user root:
UPDATE mysql.user SET authentication_string=PASSWORD('root'), plugin='mysql_native_password' WHERE User='root' AND Host='localhost';FLUSH PRIVILEGES;
exit the console:
\q
Remove (or use commentary) for that in my.cnf (we dont need that settings now):
#[mysqld]
#skip-grant-tables
restart mysql-server:
sudo service mysql restart
That's all. :)
When you installed this fresh, you usually execute
mysql_secure_installation
afterwards. There you also set the initial password for your root account (note, that this is not the root account you have in Linux).
When you installed version 5.7. or higher the initial password is not blank anymore. You can find it in the error log. Find this log by looking in your my.cnf file. Default directory is /var/log/mysql, I think.

ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES) on linux 16.04

I am new to MySQL and trying to start MySQL but I am getting this error. I also saw other solutions for same type of problem but still it is not working.
Here I tried entering my root password on Enter password prompt.
mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
As far as I know the message using password: NO only appears if you simply press Enter instead of typing in the password.
I don't have access to MySQL at the moment but, if I remember correctly, if you don't have a password (which not a good idea), you simply don't use the -p.
Now my problem is solved i followed these things:
Stopped the MySQL service
sudo /etc/init.d/mysql stop
Start MySQL without a password
sudo mysqld_safe --skip-grant-tables &
I got this error
2017-06-20T18:50:06.475664Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.
used these commands to fix it:
mkdir -p /var/run/mysqld
chown mysql:mysql /var/run/mysqld
then followed these commands:
sudo mysqld_safe --skip-grant-tables &
mysql -uroot
use mysql;
update user set password=PASSWORD("mynewpassword") where User='root';
flush privileges;
quit
And it started working.

Unable to log into mysql as root on OpenWRT

I finally decided to post my question as I am encountering high difficulties to connect to the mysql client.
I am using a mySQL database on an OpenWRT OS installed on an Arduino Yun.
I cannot log into mySQL as root, the following error message is displayed:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using
password: NO)
I tried with suffix -u root (or -uroot) and suffix -p and a supposed password but every time it turns out to be the same error, sometimes with (using password: NO), other times with (using password: YES)
Reading some posts, I tried all the following manipulation :
kill mysqld and then run
mysqld with --skip-grant-tables
It works and I can log into mysql but any operation proposed to UPDATE the password for user root turns a QUERY OK with 0 rows modified. It should be normal I suppose, as I am not log with grant tables I have no access to user informations and privileges.
Note that when I run
SELECT user();
or
SELECT current_user();
I get root# with nothing following.
Re-installing the databases using the script mysql_install_db. It does not work as is saying that no host "Arduino" or "localhost"could be looked up with /usr/bin/resolveip (nota: no such thing in that folder)
using the --force option it works.
I tried what is exposed in the following post SOLVED - MySQL - Can't Log In - Access Denied - Brand New Installation (OpenWRT)
With the command line
mysqladmin -uroot password pwd
I ended with the same answer :
error: 'Access denied for user 'root'#'localhost' (using password:
NO)'
Could anybody help me or tell me what is the cleanest way to uninstall and fully reinstall MySQL on OpenWRT?
Thank you
Well, yeah...
mysqladmin -uroot password pwd
^--missing --
Since you don't specify the password option correctly, you're effectively passing NO password to mysqladmin, and it doesn't log you in.
Try
mysqladmin -u root -p pwd
mysqladmin --user=root --password=pwd
instead.

Access denied while running Mysql for the first time on Centos

I just installed Mysql for the first time on a CentOS machine using yum. The installation had no errors. Then I followed those steps:
$ sudo /sbin/service mysqld start --skip-grant-tables --skip-networking
$ sudo /usr/bin/mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
Enter current password for root (enter for none):
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
Enter current password for root (enter for none):
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
Enter current password for root (enter for none):
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
Enter current password for root (enter for none):
It can be seen that even after first installation there is issue in logging in to the DB. I have even tried all command in sudo, but the error is still there. I can't even figure out how to reconfigure MySQL. I halso have installed-removed mysql 3 times.
How can I solve this issue?
Just for anyone who has this issue on MySQL 5.7. or higher.
MySQL v 5.7 or higher generates a temporary random password after installation and stored that in mysql error log file, located at /var/log/mysqld.log
for an installation by the MySQL Yum repository on CentOS 7.
use below command to see the password:
sudo grep 'temporary password' /var/log/mysqld.log
Ref: MySQL 5.7.7 - Centos 7 el7 - Access denied
EDIT1
For anyone that has different error log file, you can find it using #Drew's answer here below.
Maybe you already setted it at some point. You can try this:
yum remove mysql-server
rm -rf /var/lib/mysql
yum install mysql-server
systemctl start mysqld.service
/usr/bin/mysql_secure_installation
Anyway, I think this question should be in ServerFault.
A visual of the temporary root password written to the Error Log file
Not that one can exactly rifle off the command
select ##log_error;
to find the location of the Error Log file without logging in (a which came first, the chicken or the egg predicament).
But the typical locations are
C:\ProgramData\MySQL\MySQL Server 5.7\Data\
(for Windows. You must unhide the C:\ProgramData dir)
and
mysql> select ##log_error;
+---------------------+
| ##log_error |
+---------------------+
| /var/log/mysqld.log |
+---------------------+
(for Linux)
sudo mysql_secure_installation
When it asks for password type pass
Follow the prompts to change the root password
you misunderstood. Because of you havn't set the password yet. you should just
enter for none.
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Unable to login to MySQL

I installed MySQL using the following command:
sudo apt-get install mysql-server mysql-client mysql-common
It asks me for a root password (On package configuration), I enter one and confirm it.
sudo /etc/init.d/mysql start
However when I try logging in to mysql with user root and password which I supplied in the previous step, it denies me access:
root#mbilwebh02:/etc# > mysql --user root --password
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES).
Another attempt that I made was to uninstall and reinstall mysql without supplying a password but that fails as well.
I then switched the user on the server to mysql
root#mbilwebh02:/etc# sudo -u mysql -s
root#mbilwebh02:/etc# sudo -u mysql -s
bash: /root/.bashrc: Permission denied
mysql#mbilwebh02:/etc$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
At this point I am able to only start and stop mysql. Any ideas where I might be going wrong?
[EDIT]
After searching a lot I found that one can log in to mysql using debian-sys-maint as user and password which is in the debian.cnf file. There was no 'root' user in the mysql database hence everything I tried denied me access.
I do not know if this is a safe way to do it though.
Taken from: http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html
Stop mysqld and restart it with the --skip-grant-tables option. This enables anyone to connect without a password and with all privileges. Because this is insecure, you might want to use --skip-grant-tables in conjunction with --skip-networking to prevent remote clients from connecting.
Connect to the mysqld server with this command:
shell> mysql
Issue the following statements in the mysql client. Replace the password with the password that you want to use.
mysql> UPDATE mysql.user SET Password=PASSWORD('MyNewPass')
-> WHERE User='root';
mysql> FLUSH PRIVILEGES;
The FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.
You should now be able to connect to the MySQL server as root using the new password. Stop the server, then restart it normally (without the --skip-grant-tables and --skip-networking options).