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

I know the title looks familiar but no. I was working on a web app, and when I ran it, it says: Access denied for user 'root'#'localhost' (using password: NO). I searched some sites and they said that I should use a password. So I changed the password using mysql console. Than I got this message Access denied for user 'root'#'localhost' (using password: YES). And when I reenter the mysql console and put the password it makes a beep than it is closed. I got this event log:
Log Name: Application
Source: .NET Runtime
Date: 10/18/2015 7:12:51 PM
Event ID: 1026 Task Category: None Level: Error Keywords:
Classic User: N/A Computer: TOSHIBA-TOSH Description:
Application: MySQLWorkbench.exe Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Runtime.Remoting.RemotingException Stack: at
System.Runtime.Remoting.Channels.Ipc.IpcServerChannel.StartListening(System.Object)
at
MySQL.Workbench.ApplicationInstanceManager.RegisterRemoteType(System.String)
at
MySQL.Workbench.ApplicationInstanceManager.CreateSingleInstance(System.String,
System.String[],
System.EventHandler`1)
at MySQL.GUI.Workbench.Program.Main(System.String[])
Event Xml:
1026
2
0
0x80000000000000
537897
Application
TOSHIBA-TOSH
Application: MySQLWorkbench.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled
exception. Exception Info: System.Runtime.Remoting.RemotingException
Stack: at
System.Runtime.Remoting.Channels.Ipc.IpcServerChannel.StartListening(System.Object)
at
MySQL.Workbench.ApplicationInstanceManager.RegisterRemoteType(System.String)
at
MySQL.Workbench.ApplicationInstanceManager.CreateSingleInstance(System.String,
System.String[],
System.EventHandler`1<MySQL.Workbench.InstanceCallbackEventArgs>)
at MySQL.GUI.Workbench.Program.Main(System.String[])
Any help ? I uninstalled everything (wamp, mysql, dreamweaver,.........) but still got the same problem. And mysql workbench give this error when i enter the password .
I tried to use config.inc.php solutions but still the same.

Please follow below steps:
Go to mysql server console and follow below steps:
Step1: open your config file and add below lines in [mysqld] section and save file.
skip-grant-tables
skip-networking
Step2: Restart your mysql service, you can use below command if using linux.
service mysqld restart
Step3: Now connect mysql by below command-
mysql -uroot
Step4: Above command will connect you with mysql and will show mysql prompt like below-
mysql>
Step5: Now change root password as per below-
mysql> update mysql.user set password = password('root123') where user='root';
OR
mysql> update mysql.user set password = password('root123') where user='root' and host = 'localhost';
mysql> flush privileges;
mysql> exit;
Step6: Now remove newly added lines from config file and restart mysql service again as per step2.
Finally now you can connect your web or phpmyadmin with root user.

Maybe root from localhost has not the required grant to access the DB.
Try to run the following on a mysql console:
GRANT ALL ON <yourdb>.* TO 'root'#'localhost';
FLUSH PRIVILEGES;

Related

Authentication method in php for mysql is unknown? [duplicate]

This question already has answers here:
php mysqli_connect: authentication method unknown to the client [caching_sha2_password]
(17 answers)
Closed 3 years ago.
I'm running MySQL version 8 on PHP 7.0.
I'm getting the following error when I try to connect to my database from PHP:
Connect Error: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
PHP might show this error
Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in D:\xampp\htdocs\reg\server.php on line 10
How can I fix this problem?
#mohammed, this is usually attributed to the authentication plugin that your mysql database is using.
By default and for some reason, mysql 8 default plugin is auth_socket. Applications will most times expect to log in to your database using a password.
If you have not yet already changed your mysql default authentication plugin, you can do so by:
1. Log in as root to mysql
2. Run this sql command:
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password
BY 'password';
Replace 'password' with your root password. In case your application does not log in to your database with the root user, replace the 'root' user in the above command with the user that your application uses.
Digital ocean expounds some more on this here Installing Mysql
You have to change MySQL settings.
Edit my.cnf file and put this setting in mysqld section:
[mysqld]
default_authentication_plugin= mysql_native_password
Then run following command:
FLUSH PRIVILEGES;
Above command will bring into effect the changes of default authentication mechanism.
I've tried a lot of other solutions, but only this works for me.
Thanks for the workaround.
Check your .env
MYSQL_VERSION=latest
Then type this command
$ docker-compose exec mysql bash
$ mysql -u root -p
(login as root)
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
ALTER USER 'root'#'%' IDENTIFIED WITH mysql_native_password BY 'root';
ALTER USER 'default'#'%' IDENTIFIED WITH mysql_native_password BY 'secret';
Then go to phpmyadmin and login as :
host -> mysql
user -> root
password -> root
None of the answers here worked for me. What I had to do is:
Re-run the installer.
Select the quick action 're-configure' next to product 'MySQL Server'
Go through the options till you reach Authentication Method and select 'Use Legacy Authentication Method'
After that it works fine.
Faced the same problem, I was not able to run wordpress docker container with mysql version 8 as its default authentication mechanism is caching_sha2_password instead of mysql_native_password.
In order to fix this problem we must reset default authentication mechanism to mysql_native_password.
Find my.cnf file in your mysql installation, usually on a linux machine it is at the following location - /etc/mysql
Edit my.cnf file and add following line just under heading [mysqld]
default_authentication_plugin= mysql_native_password
Save the file then log into mysql command line using root user
run command FLUSH PRIVILEGES;
I'm using Laravel Lumen to build a small application.
For me it was because I didn't had the DB_USERNAME defined in my .env file.
DB_USERNAME=root
Setting this solved my problem.
In my.cnf file check below 2 steps.
check this value -
old_passwords=0;
it should be 0.
check this also-
[mysqld] default_authentication_plugin= mysql_native_password Another
value to check is to make sure
[mysqld] section should be like this.
preferences -> mysql -> initialize database -> use legacy password encryption(instead of strong) -> entered same password
as my config.inc.php file, restarted the apache server and it worked. I was still suspicious about it so I stopped the apache and mysql server and started them again and now it's working.

Authentication Failure When Connecting to MySQL as Non-Root User

My login attempts fail for a new user account that I have created, and I have spent several hours learning how authentication is handled by MySQL, but ultimately I think I'm just not fully understanding how all the components fit together regarding MySQL Server's authentication logic.
All on the same server:
MySQL 5.7
phpMyAdmin 4.9
Ubuntu 18.04
Additional info:
There are no users with blank usernames in the table mysql.user
The password doesn't have special characters
I've tried localhost, 127.0.0.1 and the actual hostname itself
/var/log/mysql/error.log only shows the exact same error message
CREATING THE USER
This is done by either:
phpMyAdmin GUI > SQL tab:
flush privileges;
create user 'testuser'#'localhost' identified by 'password!';
grant * on inventory to 'testuser'#'localhost';
flush privileges;
phpMyAdmin GUI > User Account tab > Add User Account
ssh into the Ubuntu server and create the user from the mysql command line (as root)
Regardless of how I do it, I can create the user successfully, but I'm unable to authenticate.
AUTHENTICATING THE USER
Here's the two ways I've tried:
1) From an ssh session on the Ubuntu server:
mysql -u testuser -p
mysql -u testuser - h 127.0.0.1 -p
mysql -u testuser - h localhost -p
mysql -u testuser - h -p
2) Run connect.php from another machine using (IE / Chrome / FF):
<?php
$dbhost='localhost';
$dbuser='testuser';
$dbpass='password';
$dbname='inventory';
$conn = new mysqli($dbhost,$dbuser,$dbpass,$dbname);
if($conn->connect_error) {
die("Error: Couldn't connect: ".$conn->connect_error);
}
?>
2)
Depending on whether I used 'testuser'#'%' or 'testuser'#'localhost' I'll get one of two errors:
Access denied for user 'testuser'#'%' (using password: YES)
Access denied for user 'testuser'#'localhost' (using password: YES)
To rule out this being a permissions issue, I assigned the user all global permissions, but the error message didn't change, so I reverted the change.
Running select host,user,plugin,authentication_string,account_locked from mysql.user where user='testuser'; shows:
host localhost
user testuser
plugin mysql_native_password
authentication_string blahblahblah
account_locked N
Try granting permissions like this:
GRANT ALL ON inventory.* TO 'testuser'#'localhost';

MySQL Emoncms PHP Error: User Password:NO

I'm trying to get Emoncms working on a shared hosting MediaTemple web server with verified prerequisites like mod_rewrite and LAMP server. I've created the database with user and password, configured the settings.php to the best of my ability.
/ - this is root
/emoncmsdata - Its 777 for data folders /phpfina & /phpfiwa & /phptimeseries
/httpdocs - this is my public folder
/httpdocs/emoncms - this is where the settings.php is and where modules are
But when I access santiapps.com/emoncms/ I get:
Can’t connect to database, please verify credentials/configuration in settings.php
Error message: Access denied for user ‘marskoko’#‘localhost’ (using password: NO).
I've put the database, user and password in the script. I've checked it and reset the password through their plesk.
I know the password for that user is correct because I can log in with the password just fine via terminal using mysql -u user -p pass and I get the MariaDB server and I can then enter USE Emoncms and the prompt reads that I'm connected to Emoncms.
The emoncms.log file created by the application is empty. I found a bunch of these in the web server error.log:
[Fri Sep 28 20:53:23.620729 2018] [proxy_fcgi:error] [pid 8219:tid 140039956670208] [client 83.139.179.122:35214] AH01071: Got error ‘Primary script unknown\n’
I've checked most of the posts in SO about this user password:NO issue and they all pertain to root, which I am not. I'm using another user called marskoko.
Access denied for user 'root'#'localhost' (using password: NO)?Unable to authenticate php/Mysql?
I can't stop or start the server, I've tried service mysql stop and I get:
Redirecting to /bin/systemctl stop mysql.service
Failed to stop mysql.service: Unit mysql.service not loaded.
4.a) I have recently been suggested to try:
service mysqld restart
But I get a similar error:
Redirecting to /bin/systemctl restart mysqld.service
Failed to restart mysqld.service: Unit not found.
But I know its running, otherwise I wouldn't be able to view my other databases.
I've created this php file:
<?php
$db = mysqli_connect("localhost","marskoko","myPasshasAdollarSign") or die("Failed to open connection to MySQL server.");
mysqli_select_db($db, "emoncms") or die("Unable to select database");
\>
and ran it and I get this:
Failed to open connection to MySQL server.
5.a) When I use mysqli_connect_error() I get:
Access denied for user 'emonuser'#'localhost' (using password: NO)
NOTE: The user is different because I wanted to make sure there wasn't some issue with the db or user, so I deleted the db and re-created it and changed the username. The db is still there and I can still access it via MariaDB using mysql command and the same password.
I tried this suggestion:
ps aux | grep mysql
and I get this:
mysql 7766 0.0 0.0 113200 1588 ? Ss Sep28 0:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
mysql 8286 0.7 5.4 1906888 457400 ? Sl Sep28 5:12 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/lib/mysql/activacorp.net.err --pid-file=activacorp.net.pid --socket=/var/lib/mysql/mysql.sock --port=3306
root 15702 0.0 0.0 112600 1068 pts/0 S+ 09:17 0:00 grep --color=auto mysql
I just tried logging into the db with the user/pass and I tried getting the table of users but got this:
MariaDB [emoncms]> select * from user;
ERROR 1146 (42S02): Table 'emoncms.user' doesn't exist
Then again I just checked all my databases and neither have the users table in it. They have other tables which Ive added and work with, but not the user table. Maybe phpmyadmin hides that, I dunno.
I dunno what else to try.
i think you can resolve this by the steps following
start/stop mysql by using service mysqld start/stop/restart instead of service mysql start/stop/restart
make sure you got the right password for mysql user - root, if no, please reset password by following step 3, else, skip step 3
edit mysql config file, usually /etc/my.cny, add skip-grant-tables under [mysqld], then restart mysql, now you can go into mysql without password, then reset password by using
update mysql.user set authentication_string=password('123qwe') where user='root' and Host = 'localhost';
flush privileges;
that is all, please check it
Ok I figured it out. Digging around the php I tried logging the $password variable in the index.php of emoncms and it logged blank whilst the username, database or other variables logged correctly. I ended up replacing the $password for the actual password in the mysqli line and it works now. So then I just replaced the $password "" for '' and it works now.

PHP with MySQL 8.0+ error: The server requested authentication method unknown to the client [duplicate]

This question already has answers here:
php mysqli_connect: authentication method unknown to the client [caching_sha2_password]
(17 answers)
Closed 3 years ago.
I'm running MySQL version 8 on PHP 7.0.
I'm getting the following error when I try to connect to my database from PHP:
Connect Error: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
PHP might show this error
Warning: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in D:\xampp\htdocs\reg\server.php on line 10
How can I fix this problem?
#mohammed, this is usually attributed to the authentication plugin that your mysql database is using.
By default and for some reason, mysql 8 default plugin is auth_socket. Applications will most times expect to log in to your database using a password.
If you have not yet already changed your mysql default authentication plugin, you can do so by:
1. Log in as root to mysql
2. Run this sql command:
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password
BY 'password';
Replace 'password' with your root password. In case your application does not log in to your database with the root user, replace the 'root' user in the above command with the user that your application uses.
Digital ocean expounds some more on this here Installing Mysql
You have to change MySQL settings.
Edit my.cnf file and put this setting in mysqld section:
[mysqld]
default_authentication_plugin= mysql_native_password
Then run following command:
FLUSH PRIVILEGES;
Above command will bring into effect the changes of default authentication mechanism.
I've tried a lot of other solutions, but only this works for me.
Thanks for the workaround.
Check your .env
MYSQL_VERSION=latest
Then type this command
$ docker-compose exec mysql bash
$ mysql -u root -p
(login as root)
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
ALTER USER 'root'#'%' IDENTIFIED WITH mysql_native_password BY 'root';
ALTER USER 'default'#'%' IDENTIFIED WITH mysql_native_password BY 'secret';
Then go to phpmyadmin and login as :
host -> mysql
user -> root
password -> root
None of the answers here worked for me. What I had to do is:
Re-run the installer.
Select the quick action 're-configure' next to product 'MySQL Server'
Go through the options till you reach Authentication Method and select 'Use Legacy Authentication Method'
After that it works fine.
Faced the same problem, I was not able to run wordpress docker container with mysql version 8 as its default authentication mechanism is caching_sha2_password instead of mysql_native_password.
In order to fix this problem we must reset default authentication mechanism to mysql_native_password.
Find my.cnf file in your mysql installation, usually on a linux machine it is at the following location - /etc/mysql
Edit my.cnf file and add following line just under heading [mysqld]
default_authentication_plugin= mysql_native_password
Save the file then log into mysql command line using root user
run command FLUSH PRIVILEGES;
I'm using Laravel Lumen to build a small application.
For me it was because I didn't had the DB_USERNAME defined in my .env file.
DB_USERNAME=root
Setting this solved my problem.
In my.cnf file check below 2 steps.
check this value -
old_passwords=0;
it should be 0.
check this also-
[mysqld] default_authentication_plugin= mysql_native_password Another
value to check is to make sure
[mysqld] section should be like this.
preferences -> mysql -> initialize database -> use legacy password encryption(instead of strong) -> entered same password
as my config.inc.php file, restarted the apache server and it worked. I was still suspicious about it so I stopped the apache and mysql server and started them again and now it's working.

beginner having troubles working on mysql

I am teaching myself how to code by watching Kevin Skoglund movies on Lynda. I am having troubles on one of the chapters in the series - creating a database. I am trying to log on to MySQL but is showing like this-
Rosss-MacBook-Air:~ rossnyland$ mysql -user -p
Enter password:
ERROR 1045 (28000): Access denied for user 'ser'#'localhost' (using password: YES)
Rosss-MacBook-Air:~ rossnyland$
The password is right because when I type a wrong password it will say (using password: NO)
What am I doing wrong? MySQL server is running, I'm using 5.7.20 version, using MAC OS x, and have tried to log on on mysqlworkbench, but message pops up saying this
Your connection attempt failed for user 'root' from your host to server at localhost:3306:
Access denied for user 'root'#'localhost' (using password: YES)
Please:
1 Check that mysql is running on server localhost
2 Check that mysql is running on port 3306 (note: 3306 is the default, but this can be changed)
3 Check the root has rights to connect to localhost from your address (mysql rights define what clients can connect to the server and from which machines)
4 Make sure you are both providing a password if needed and using the correct password for localhost connecting from the host address you're connecting from
Even I tried to delete it but no success! Please tell me what am I doing wrong or how to start over again...
The password could be right, but I doubt your user is ser.
When you use the command-line option -u, any text you put after it, is the username.
So if your username for mysql is mysql_user, you need:
$ mysql -umysql_user -p
or:
$ mysql -u mysql_user -p
or:
$ mysql --user=mysql_user --password
For the Command Line Tool error, you probably provided the wrong command. It should be:
$ mysql -u username -p
For the MySQL Workbench error, there are two possibilities:
You provided the wrong password for 'root'#'localhost'. Or the user 'root'#'localhost' didn't exist.
Your MySQL server didn't listen on the localhost interface. In other words, check the value of bind_ip in your my.cnf config file. You should provide the actual ip address by --host option in this case.
You can also check this answer I posted before, it shows you the full steps to solve this kind of problems.

Categories