I just wiped my Mac and did a fresh install of El Capitan. I'm struggling to connect to Mysql now. Having gone through a web server setup process, I've created a simple PHP test file:
<?php
$conn = new mysqli("127.0.0.1", "root", "xxxxxxxx");
if ($conn->connect_error) echo "Connection failed: " . $conn->connect_error;
else echo "Connected successfully";
phpinfo();
?>
When I run it, I get this error:
Warning: mysqli::mysqli(): (HY000/1862): Your password has expired. To log in you must change it using a client that supports expired passwords. in /Users/rich/Documents/DESIGN/test/index.php on line 3
Connection failed: Your password has expired. To log in you must change it using a client that supports expired passwords.
I've never seen that response from a connection before. How do I fix it if I can't connect?
EDIT
In terminal I entered the command:
mysql -u root -p
This asked me for my password (current one) which I put in. I now have access to mysql commands but anything I try results in this error:
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
How do I reset the password using ALTER USER?
So I finally found the solution myself.
Firstly I went into terminal and typed:
mysql -u root -p
This asked for my current password which I typed in and it gave me access to provide more mysql commands. Anything I tried from here gave this error:
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
This is confusing because I couldn't actually see a way of resetting the password using ALTER USER statement, but I did find another simple solution:
SET PASSWORD = PASSWORD('xxxxxxxx');
First, I use:
mysql -u root -p
Giving my current password for the 'root'.
Next:
mysql> ALTER USER `root`#`localhost` IDENTIFIED BY 'new_password',
`root`#`localhost` PASSWORD EXPIRE NEVER;
Change 'new_password' to a new password for the user 'root'.
It solved my problem.
mysqladmin -u [username] -p password worked for me on OS X El Capitan and MySQL 5.7.12 Community Server. Example:
$ /usr/local/mysql/bin/mysqladmin -u root -p password
Enter password:
New password:
Confirm new password:
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
This is similar to pavan sachi's answer, but with password prompts.
My error was "#1862 - Your password has expired. To log in you must change it using a client that supports expired passwords." at phpMyAdmin login screen first time.
MySQL password expiry
Resetting the password will only solve the problem temporarily. From MySQL 5.7.4 to 5.7.10 (to encourage better security - see MySQL: Password Expiration Policy) the default default_password_lifetime variable value is 360 (1 year-ish). For those versions, if you make no changes to this variable (or to individual user accounts) all passwords expire after 360 days.
So from a script you might get the message: "Your password has expired. To log in you must change it using a client that supports expired passwords."
To stop automatic password expiry, log in as root (mysql -u root -p), then, for clients that automatically connect to the server (e.g. scripts.) change password expiration settings:
ALTER USER 'script'#'localhost' PASSWORD EXPIRE NEVER;
OR you can disable automatic password expiration for all users:
SET GLOBAL default_password_lifetime = 0;
As pointed out by Mertaydin in the comments, to make this permanent add the following line to a my.cnf file MySQL reads on startup, under the [mysqld] group of settings. The location of my.cnf depends on your setup (e.g. Windows, or Homebrew on OS X, or an installer), and whether you want this per-user on Unix or global:
[mysqld]
default_password_lifetime = 0
(There may be other settings here too...)
See the MySQL docs on configuration files.
I went through the same issue recently while installing mysql on mac os x capitan.
I did not find the correct answer here, so adding this answer.
MySql in current versions, generates a temporary password when you install mysql. Use this password to set a new password using the mysqladmin utility as below;
/usr/local/mysql/bin/mysqladmin -u root -p'<your temp password>' password '<your new password>'
Hope it helps you and others.
This worked for me:
ALTER USER 'root'#'localhost' IDENTIFIED BY 'yourpassword','root'#'localhost' PASSWORD EXPIRE NEVER;
Just download MySQL workbench to log in. It will prompt you to change the password immediately and automatically.
On Windows in phpmyadmin look in Variables: default_password_lifetime, and switch it to 0 (instead of 360), enjoy.
Its possible than mySQL take again 360 days, so add in my.ini :
[mysqld]
default_password_lifetime=0
And restart mysql.
start MYSQL in safe mode
mysqld_safe --skip-grant-tables &
Connect to MYSQL server
mysql -u root
run SQL commands to reset password:
use mysql;
SET GLOBAL default_password_lifetime = 0;
SET PASSWORD = PASSWORD('new_password');
Last step, restart your mysql service
i have faced this issue few days ago. For best solution for 5.7 version of MySQL; login your mysql console and alter your password with the following command:
ALTER USER `root`#`localhost` IDENTIFIED BY 'new_password', `root`#`localhost` PASSWORD EXPIRE NEVER;
WARNING: this will allow any user to login
I had to try something else. Since my root password expired and altering was not an option because
Column count of mysql.user is wrong. Expected 45, found 46. The table is probably corrupted
temporarly adding skip-grant-tables under [mysqld] in my.cnf and restarting mysql did the trick
All of these answers are using Linux consoles to access MySQL.
If you are on Windows and are using WAMP, you can start by opening the MySQL console (click WAMP icon->MySQL->MySQL console).
Then it will request you to enter your current password, enter it.
And then type SET PASSWORD = PASSWORD('some_pass');
restart MySQL server with --skip-grant-tables option
And then set a new root password
$ mysql -u root
mysql> USE mysql;
mysql> UPDATE user SET password=PASSWORD("NEWPASSWORD") WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
Now if you need, you can update mysql.user table(field password_expired='N') not to expire the password.
best easy solution:
[PATH MYSQL]/bin/mysql -u root
[Enter password]
SET GLOBAL default_password_lifetime = 0;
and then works fine.
This work for me:
Source: https://www.diariodeunprogramador.net/fallo-al-conectar-mysql-your-password-expired/
Login as root:
mysql -u root -p
and then you deactivate the automatic expiration of passwords of all the users:
SET GLOBAL default_password_lifetime = 0;
On DBeaver, Edit Connection -> Driver Properties -> disable disconnectOnExpiredPasswords:
Reconnect and:
And execute:
SET PASSWORD FOR 'user-name'#'localhost' = PASSWORD('NEW_USER_PASSWORD');
FLUSH PRIVILEGES;
The password expiration is a new feature in MySQL 5.6 or 5.7.
The answer is clear: Use a client which is capable of expired password changing (I think Sequel Pro can do it).
MySQLi library obviously isnt able to change the expired password.
If you have limited access to localhost and you only have a console client, the standard mysql client can do it.
Open MySQL console and type SET PASSWORD = 'your password';
and then press ENTER Key which will set your defined password for user root.
You can only write SET PASSWORD = '';
which will set password as blank for root user.
I did something like this.
UPDATE mysql.user SET authentication_string = PASSWORD(''), password_expired = 'N' WHERE User = 'root' AND Host = 'localhost';
For MySQL 8.0 +, if you get this error,
*Your password has expired. To log in you must change it using a client that
supports expired passwords.*
you need use current user , to open mysql terminal, then use
SET PASSWORD ='123456'; To get a new password 123456 for current user;
Don't use SET PASSWORD = PASSWORD('123456'); This one have been deprecated in MySQL 8.0+;
Just open MySQL Workbench and choose [Instance] Startup/Shutdown and click on start server.
It worked for me
Related
I am using php mysqli_connect for login to a MySQL database (all on localhost)
<?php
//DEFINE ('DB_USER', 'user2');
//DEFINE ('DB_PASSWORD', 'pass2');
DEFINE ('DB_USER', 'user1');
DEFINE ('DB_PASSWORD', 'pass1');
DEFINE ('DB_HOST', '127.0.0.1');
DEFINE ('DB_NAME', 'dbname');
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if(!$dbc){
die('error connecting to database');
}
?>
this is the mysql.user table:
MySQL Server ini File:
[mysqld]
# The default authentication plugin to be used when connecting to the server
default_authentication_plugin=caching_sha2_password
#default_authentication_plugin=mysql_native_password
with caching_sha2_password in the MySQL Server ini file, it's not possible at all to login with user1 or user2;
error: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in...
with mysql_native_password in the MySQL Server ini file, it's possible to login with user1, but with user2, same error;
how can I login using caching_sha2_password on the mySql Server?
I solve this by SQL command:
ALTER USER 'mysqlUsername'#'localhost' IDENTIFIED WITH mysql_native_password BY 'mysqlUsernamePassword';
which is referenced by https://dev.mysql.com/doc/refman/8.0/en/alter-user.html
if you are creating new user
CREATE USER 'jeffrey'#'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
which is referenced by https://dev.mysql.com/doc/refman/8.0/en/create-user.html
this works for me
As of PHP 7.4, this is no longer an issue. Support for caching_sha2 authentication method has been added to mysqlnd.
Currently, PHP mysqli extension do not support new caching_sha2 authentication feature.
You have to wait until they release an update.
Check related post from MySQL developers: https://mysqlserverteam.com/upgrading-to-mysql-8-0-default-authentication-plugin-considerations/
They didn't mention PDO, maybe you should try to connect with PDO.
ALTER USER 'mysqlUsername'#'localhost' IDENTIFIED WITH mysql_native_password BY 'mysqlUsernamePassword';
Remove quotes (') after ALTER USER and keep quote (') after mysql_native_password BY
It is working for me also.
If you're on Windows and it's not possible to use caching_sha2_password at all, you can do the following:
rerun the MySQL Installer
select "Reconfigure" next to MySQL Server (the top item)
click "Next" until you get to "Authentication Method"
change "Use Strong Password Encryption for Authentication (RECOMMENDED)" to "Use Legacy Authentication Method (Retain MySQL 5.X Compatibility)
click "Next"
enter your Root Account Password in Accounts and Roles, and click "Check"
click "Next"
keep clicking "Next" until you get to "Apply Configuration"
click "Execute"
The Installer will make all the configuration changes needed for you.
Like many many people, I have had the same problem. Although the user is set to use mysql_native_password, and I can connect from the command line, the only way I could get mysqli() to connect is to add
default-authentication-plugin=mysql_native_password
to the [mysqld] section of, in my setup on ubuntu 19.10, /etc/mysql/mysql.conf.d/mysqld.cnf
It's working for me (PHP 5.6 + PDO / MySQL Server 8.0 / Windows 7 64bits)
Edit the file C:\ProgramData\MySQL\MySQL Server 8.0\my.ini:
default_authentication_plugin=mysql_native_password
Reset MySQL service on Windows, and in the MySQL Shell...
ALTER USER my_user#'%' IDENTIFIED WITH mysql_native_password BY 'password';
I ran the following command
ALTER USER 'root' # 'localhost' identified with mysql_native_password BY 'root123'; in the command line and finally restart MySQL in local services.
If you're on a Mac, here's how to fix it. This is after tons of trial and error. Hope this helps others..
Debugging:
$mysql --verbose --help | grep my.cnf
$ which mysql
/usr/local/bin/mysql
Resolution:
nano /usr/local/etc/my.cnf
Add: default-authentication-plugin=mysql_native_password
-------
# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
default-authentication-plugin=mysql_native_password
------
Finally Run: brew services restart mysql
Now you can upgrade to PHP7.4 and MySQL will go with caching_sha2_password by default, so default MySQL installation will work with mysqli_connect No configuration required.
I tried this in Ubuntu 18.04
and is the only solution that worked for me:
ALTER USER my_user#'%' IDENTIFIED WITH mysql_native_password BY 'password';
If you have not yet already changed your MySQL default authentication plugin, you can do so by:
Log in as root to MySQL
Run the following SQL command:
a. if you are running MySQL in a different server:
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password
BY 'password';
b. if you are running MySQL in a different server:
ALTER USER 'root'#'%' IDENTIFIED WITH mysql_native_password
BY 'password';
I am using laravel 5.8 and having MAMP server got this error resolved by adding DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock in .env file like below
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=8889
DB_DATABASE=dbname
DB_USERNAME=root
DB_PASSWORD=root
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
In my case when I was using WAMP server I fixed it using following
Note the port in mySQL's "my.ini" file. In my case it was changed to 3308 when I was switching b/w MariaDB and MySQL DB.
Use the port number when you create mysqli object.
Using the above steps I was able to run the program successfully.
phpMyAdmin GUI way
Note: This method may not work if you have the problem with root user account.
Login to phpMyAdmin as root.
Switch to "User Accounts" tab.
Select the username you get error with.
From the top buttons, switch to "Login Information" section.
In "Login Information" box, change "Authentication plugin" from "Caching sha2 authentication" to "Native MySQL authentication". Also, you must fill in other required fields, obviously, including username and password.
Save it by clicking on the "Go" button at the bottom.
Return back to terminal and enjoy. :)
In my case, i'm using PHP Symfony framework and it's a silly mistake.
The database credential was wrong in paramers.yml.
After changing the credentials accordingly the problem was gone.
In Digital Ocean Managed Mysql, we have an option to change encryption, you can change to legacy and it'll work ok.
I think it is not useful to configure the mysql server without caching_sha2_password encryption, we have to find a way to publish, send or obtain secure information through the network. As you see in the code below I dont use variable $db_name, and Im using a user in mysql server with standar configuration password.
Just create a Standar user password and config all privilages. it works, but how i said without segurity.
<?php
$db_name="db";
$mysql_username="root";
$mysql_password="****";
$server_name="localhost";
$conn=mysqli_connect($server_name,$mysql_username,$mysql_password);
if ($conn) {
echo "connetion success";
}
else{
echo mysqli_error($conn);
}
?>
I am using php mysqli_connect for login to a MySQL database (all on localhost)
<?php
//DEFINE ('DB_USER', 'user2');
//DEFINE ('DB_PASSWORD', 'pass2');
DEFINE ('DB_USER', 'user1');
DEFINE ('DB_PASSWORD', 'pass1');
DEFINE ('DB_HOST', '127.0.0.1');
DEFINE ('DB_NAME', 'dbname');
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if(!$dbc){
die('error connecting to database');
}
?>
this is the mysql.user table:
MySQL Server ini File:
[mysqld]
# The default authentication plugin to be used when connecting to the server
default_authentication_plugin=caching_sha2_password
#default_authentication_plugin=mysql_native_password
with caching_sha2_password in the MySQL Server ini file, it's not possible at all to login with user1 or user2;
error: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in...
with mysql_native_password in the MySQL Server ini file, it's possible to login with user1, but with user2, same error;
how can I login using caching_sha2_password on the mySql Server?
I solve this by SQL command:
ALTER USER 'mysqlUsername'#'localhost' IDENTIFIED WITH mysql_native_password BY 'mysqlUsernamePassword';
which is referenced by https://dev.mysql.com/doc/refman/8.0/en/alter-user.html
if you are creating new user
CREATE USER 'jeffrey'#'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
which is referenced by https://dev.mysql.com/doc/refman/8.0/en/create-user.html
this works for me
As of PHP 7.4, this is no longer an issue. Support for caching_sha2 authentication method has been added to mysqlnd.
Currently, PHP mysqli extension do not support new caching_sha2 authentication feature.
You have to wait until they release an update.
Check related post from MySQL developers: https://mysqlserverteam.com/upgrading-to-mysql-8-0-default-authentication-plugin-considerations/
They didn't mention PDO, maybe you should try to connect with PDO.
ALTER USER 'mysqlUsername'#'localhost' IDENTIFIED WITH mysql_native_password BY 'mysqlUsernamePassword';
Remove quotes (') after ALTER USER and keep quote (') after mysql_native_password BY
It is working for me also.
If you're on Windows and it's not possible to use caching_sha2_password at all, you can do the following:
rerun the MySQL Installer
select "Reconfigure" next to MySQL Server (the top item)
click "Next" until you get to "Authentication Method"
change "Use Strong Password Encryption for Authentication (RECOMMENDED)" to "Use Legacy Authentication Method (Retain MySQL 5.X Compatibility)
click "Next"
enter your Root Account Password in Accounts and Roles, and click "Check"
click "Next"
keep clicking "Next" until you get to "Apply Configuration"
click "Execute"
The Installer will make all the configuration changes needed for you.
Like many many people, I have had the same problem. Although the user is set to use mysql_native_password, and I can connect from the command line, the only way I could get mysqli() to connect is to add
default-authentication-plugin=mysql_native_password
to the [mysqld] section of, in my setup on ubuntu 19.10, /etc/mysql/mysql.conf.d/mysqld.cnf
It's working for me (PHP 5.6 + PDO / MySQL Server 8.0 / Windows 7 64bits)
Edit the file C:\ProgramData\MySQL\MySQL Server 8.0\my.ini:
default_authentication_plugin=mysql_native_password
Reset MySQL service on Windows, and in the MySQL Shell...
ALTER USER my_user#'%' IDENTIFIED WITH mysql_native_password BY 'password';
I ran the following command
ALTER USER 'root' # 'localhost' identified with mysql_native_password BY 'root123'; in the command line and finally restart MySQL in local services.
If you're on a Mac, here's how to fix it. This is after tons of trial and error. Hope this helps others..
Debugging:
$mysql --verbose --help | grep my.cnf
$ which mysql
/usr/local/bin/mysql
Resolution:
nano /usr/local/etc/my.cnf
Add: default-authentication-plugin=mysql_native_password
-------
# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
default-authentication-plugin=mysql_native_password
------
Finally Run: brew services restart mysql
Now you can upgrade to PHP7.4 and MySQL will go with caching_sha2_password by default, so default MySQL installation will work with mysqli_connect No configuration required.
I tried this in Ubuntu 18.04
and is the only solution that worked for me:
ALTER USER my_user#'%' IDENTIFIED WITH mysql_native_password BY 'password';
If you have not yet already changed your MySQL default authentication plugin, you can do so by:
Log in as root to MySQL
Run the following SQL command:
a. if you are running MySQL in a different server:
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password
BY 'password';
b. if you are running MySQL in a different server:
ALTER USER 'root'#'%' IDENTIFIED WITH mysql_native_password
BY 'password';
I am using laravel 5.8 and having MAMP server got this error resolved by adding DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock in .env file like below
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=8889
DB_DATABASE=dbname
DB_USERNAME=root
DB_PASSWORD=root
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
In my case when I was using WAMP server I fixed it using following
Note the port in mySQL's "my.ini" file. In my case it was changed to 3308 when I was switching b/w MariaDB and MySQL DB.
Use the port number when you create mysqli object.
Using the above steps I was able to run the program successfully.
phpMyAdmin GUI way
Note: This method may not work if you have the problem with root user account.
Login to phpMyAdmin as root.
Switch to "User Accounts" tab.
Select the username you get error with.
From the top buttons, switch to "Login Information" section.
In "Login Information" box, change "Authentication plugin" from "Caching sha2 authentication" to "Native MySQL authentication". Also, you must fill in other required fields, obviously, including username and password.
Save it by clicking on the "Go" button at the bottom.
Return back to terminal and enjoy. :)
In my case, i'm using PHP Symfony framework and it's a silly mistake.
The database credential was wrong in paramers.yml.
After changing the credentials accordingly the problem was gone.
In Digital Ocean Managed Mysql, we have an option to change encryption, you can change to legacy and it'll work ok.
I think it is not useful to configure the mysql server without caching_sha2_password encryption, we have to find a way to publish, send or obtain secure information through the network. As you see in the code below I dont use variable $db_name, and Im using a user in mysql server with standar configuration password.
Just create a Standar user password and config all privilages. it works, but how i said without segurity.
<?php
$db_name="db";
$mysql_username="root";
$mysql_password="****";
$server_name="localhost";
$conn=mysqli_connect($server_name,$mysql_username,$mysql_password);
if ($conn) {
echo "connetion success";
}
else{
echo mysqli_error($conn);
}
?>
I am using php mysqli_connect for login to a MySQL database (all on localhost)
<?php
//DEFINE ('DB_USER', 'user2');
//DEFINE ('DB_PASSWORD', 'pass2');
DEFINE ('DB_USER', 'user1');
DEFINE ('DB_PASSWORD', 'pass1');
DEFINE ('DB_HOST', '127.0.0.1');
DEFINE ('DB_NAME', 'dbname');
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if(!$dbc){
die('error connecting to database');
}
?>
this is the mysql.user table:
MySQL Server ini File:
[mysqld]
# The default authentication plugin to be used when connecting to the server
default_authentication_plugin=caching_sha2_password
#default_authentication_plugin=mysql_native_password
with caching_sha2_password in the MySQL Server ini file, it's not possible at all to login with user1 or user2;
error: mysqli_connect(): The server requested authentication method unknown to the client [caching_sha2_password] in...
with mysql_native_password in the MySQL Server ini file, it's possible to login with user1, but with user2, same error;
how can I login using caching_sha2_password on the mySql Server?
I solve this by SQL command:
ALTER USER 'mysqlUsername'#'localhost' IDENTIFIED WITH mysql_native_password BY 'mysqlUsernamePassword';
which is referenced by https://dev.mysql.com/doc/refman/8.0/en/alter-user.html
if you are creating new user
CREATE USER 'jeffrey'#'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
which is referenced by https://dev.mysql.com/doc/refman/8.0/en/create-user.html
this works for me
As of PHP 7.4, this is no longer an issue. Support for caching_sha2 authentication method has been added to mysqlnd.
Currently, PHP mysqli extension do not support new caching_sha2 authentication feature.
You have to wait until they release an update.
Check related post from MySQL developers: https://mysqlserverteam.com/upgrading-to-mysql-8-0-default-authentication-plugin-considerations/
They didn't mention PDO, maybe you should try to connect with PDO.
ALTER USER 'mysqlUsername'#'localhost' IDENTIFIED WITH mysql_native_password BY 'mysqlUsernamePassword';
Remove quotes (') after ALTER USER and keep quote (') after mysql_native_password BY
It is working for me also.
If you're on Windows and it's not possible to use caching_sha2_password at all, you can do the following:
rerun the MySQL Installer
select "Reconfigure" next to MySQL Server (the top item)
click "Next" until you get to "Authentication Method"
change "Use Strong Password Encryption for Authentication (RECOMMENDED)" to "Use Legacy Authentication Method (Retain MySQL 5.X Compatibility)
click "Next"
enter your Root Account Password in Accounts and Roles, and click "Check"
click "Next"
keep clicking "Next" until you get to "Apply Configuration"
click "Execute"
The Installer will make all the configuration changes needed for you.
Like many many people, I have had the same problem. Although the user is set to use mysql_native_password, and I can connect from the command line, the only way I could get mysqli() to connect is to add
default-authentication-plugin=mysql_native_password
to the [mysqld] section of, in my setup on ubuntu 19.10, /etc/mysql/mysql.conf.d/mysqld.cnf
It's working for me (PHP 5.6 + PDO / MySQL Server 8.0 / Windows 7 64bits)
Edit the file C:\ProgramData\MySQL\MySQL Server 8.0\my.ini:
default_authentication_plugin=mysql_native_password
Reset MySQL service on Windows, and in the MySQL Shell...
ALTER USER my_user#'%' IDENTIFIED WITH mysql_native_password BY 'password';
I ran the following command
ALTER USER 'root' # 'localhost' identified with mysql_native_password BY 'root123'; in the command line and finally restart MySQL in local services.
If you're on a Mac, here's how to fix it. This is after tons of trial and error. Hope this helps others..
Debugging:
$mysql --verbose --help | grep my.cnf
$ which mysql
/usr/local/bin/mysql
Resolution:
nano /usr/local/etc/my.cnf
Add: default-authentication-plugin=mysql_native_password
-------
# Default Homebrew MySQL server config
[mysqld]
# Only allow connections from localhost
bind-address = 127.0.0.1
default-authentication-plugin=mysql_native_password
------
Finally Run: brew services restart mysql
Now you can upgrade to PHP7.4 and MySQL will go with caching_sha2_password by default, so default MySQL installation will work with mysqli_connect No configuration required.
I tried this in Ubuntu 18.04
and is the only solution that worked for me:
ALTER USER my_user#'%' IDENTIFIED WITH mysql_native_password BY 'password';
If you have not yet already changed your MySQL default authentication plugin, you can do so by:
Log in as root to MySQL
Run the following SQL command:
a. if you are running MySQL in a different server:
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password
BY 'password';
b. if you are running MySQL in a different server:
ALTER USER 'root'#'%' IDENTIFIED WITH mysql_native_password
BY 'password';
I am using laravel 5.8 and having MAMP server got this error resolved by adding DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock in .env file like below
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=8889
DB_DATABASE=dbname
DB_USERNAME=root
DB_PASSWORD=root
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
In my case when I was using WAMP server I fixed it using following
Note the port in mySQL's "my.ini" file. In my case it was changed to 3308 when I was switching b/w MariaDB and MySQL DB.
Use the port number when you create mysqli object.
Using the above steps I was able to run the program successfully.
phpMyAdmin GUI way
Note: This method may not work if you have the problem with root user account.
Login to phpMyAdmin as root.
Switch to "User Accounts" tab.
Select the username you get error with.
From the top buttons, switch to "Login Information" section.
In "Login Information" box, change "Authentication plugin" from "Caching sha2 authentication" to "Native MySQL authentication". Also, you must fill in other required fields, obviously, including username and password.
Save it by clicking on the "Go" button at the bottom.
Return back to terminal and enjoy. :)
In my case, i'm using PHP Symfony framework and it's a silly mistake.
The database credential was wrong in paramers.yml.
After changing the credentials accordingly the problem was gone.
In Digital Ocean Managed Mysql, we have an option to change encryption, you can change to legacy and it'll work ok.
I think it is not useful to configure the mysql server without caching_sha2_password encryption, we have to find a way to publish, send or obtain secure information through the network. As you see in the code below I dont use variable $db_name, and Im using a user in mysql server with standar configuration password.
Just create a Standar user password and config all privilages. it works, but how i said without segurity.
<?php
$db_name="db";
$mysql_username="root";
$mysql_password="****";
$server_name="localhost";
$conn=mysqli_connect($server_name,$mysql_username,$mysql_password);
if ($conn) {
echo "connetion success";
}
else{
echo mysqli_error($conn);
}
?>
I just wiped my Mac and did a fresh install of El Capitan. I'm struggling to connect to Mysql now. Having gone through a web server setup process, I've created a simple PHP test file:
<?php
$conn = new mysqli("127.0.0.1", "root", "xxxxxxxx");
if ($conn->connect_error) echo "Connection failed: " . $conn->connect_error;
else echo "Connected successfully";
phpinfo();
?>
When I run it, I get this error:
Warning: mysqli::mysqli(): (HY000/1862): Your password has expired. To log in you must change it using a client that supports expired passwords. in /Users/rich/Documents/DESIGN/test/index.php on line 3
Connection failed: Your password has expired. To log in you must change it using a client that supports expired passwords.
I've never seen that response from a connection before. How do I fix it if I can't connect?
EDIT
In terminal I entered the command:
mysql -u root -p
This asked me for my password (current one) which I put in. I now have access to mysql commands but anything I try results in this error:
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
How do I reset the password using ALTER USER?
So I finally found the solution myself.
Firstly I went into terminal and typed:
mysql -u root -p
This asked for my current password which I typed in and it gave me access to provide more mysql commands. Anything I tried from here gave this error:
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
This is confusing because I couldn't actually see a way of resetting the password using ALTER USER statement, but I did find another simple solution:
SET PASSWORD = PASSWORD('xxxxxxxx');
First, I use:
mysql -u root -p
Giving my current password for the 'root'.
Next:
mysql> ALTER USER `root`#`localhost` IDENTIFIED BY 'new_password',
`root`#`localhost` PASSWORD EXPIRE NEVER;
Change 'new_password' to a new password for the user 'root'.
It solved my problem.
mysqladmin -u [username] -p password worked for me on OS X El Capitan and MySQL 5.7.12 Community Server. Example:
$ /usr/local/mysql/bin/mysqladmin -u root -p password
Enter password:
New password:
Confirm new password:
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
This is similar to pavan sachi's answer, but with password prompts.
My error was "#1862 - Your password has expired. To log in you must change it using a client that supports expired passwords." at phpMyAdmin login screen first time.
MySQL password expiry
Resetting the password will only solve the problem temporarily. From MySQL 5.7.4 to 5.7.10 (to encourage better security - see MySQL: Password Expiration Policy) the default default_password_lifetime variable value is 360 (1 year-ish). For those versions, if you make no changes to this variable (or to individual user accounts) all passwords expire after 360 days.
So from a script you might get the message: "Your password has expired. To log in you must change it using a client that supports expired passwords."
To stop automatic password expiry, log in as root (mysql -u root -p), then, for clients that automatically connect to the server (e.g. scripts.) change password expiration settings:
ALTER USER 'script'#'localhost' PASSWORD EXPIRE NEVER;
OR you can disable automatic password expiration for all users:
SET GLOBAL default_password_lifetime = 0;
As pointed out by Mertaydin in the comments, to make this permanent add the following line to a my.cnf file MySQL reads on startup, under the [mysqld] group of settings. The location of my.cnf depends on your setup (e.g. Windows, or Homebrew on OS X, or an installer), and whether you want this per-user on Unix or global:
[mysqld]
default_password_lifetime = 0
(There may be other settings here too...)
See the MySQL docs on configuration files.
I went through the same issue recently while installing mysql on mac os x capitan.
I did not find the correct answer here, so adding this answer.
MySql in current versions, generates a temporary password when you install mysql. Use this password to set a new password using the mysqladmin utility as below;
/usr/local/mysql/bin/mysqladmin -u root -p'<your temp password>' password '<your new password>'
Hope it helps you and others.
This worked for me:
ALTER USER 'root'#'localhost' IDENTIFIED BY 'yourpassword','root'#'localhost' PASSWORD EXPIRE NEVER;
Just download MySQL workbench to log in. It will prompt you to change the password immediately and automatically.
On Windows in phpmyadmin look in Variables: default_password_lifetime, and switch it to 0 (instead of 360), enjoy.
Its possible than mySQL take again 360 days, so add in my.ini :
[mysqld]
default_password_lifetime=0
And restart mysql.
start MYSQL in safe mode
mysqld_safe --skip-grant-tables &
Connect to MYSQL server
mysql -u root
run SQL commands to reset password:
use mysql;
SET GLOBAL default_password_lifetime = 0;
SET PASSWORD = PASSWORD('new_password');
Last step, restart your mysql service
i have faced this issue few days ago. For best solution for 5.7 version of MySQL; login your mysql console and alter your password with the following command:
ALTER USER `root`#`localhost` IDENTIFIED BY 'new_password', `root`#`localhost` PASSWORD EXPIRE NEVER;
WARNING: this will allow any user to login
I had to try something else. Since my root password expired and altering was not an option because
Column count of mysql.user is wrong. Expected 45, found 46. The table is probably corrupted
temporarly adding skip-grant-tables under [mysqld] in my.cnf and restarting mysql did the trick
All of these answers are using Linux consoles to access MySQL.
If you are on Windows and are using WAMP, you can start by opening the MySQL console (click WAMP icon->MySQL->MySQL console).
Then it will request you to enter your current password, enter it.
And then type SET PASSWORD = PASSWORD('some_pass');
restart MySQL server with --skip-grant-tables option
And then set a new root password
$ mysql -u root
mysql> USE mysql;
mysql> UPDATE user SET password=PASSWORD("NEWPASSWORD") WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
Now if you need, you can update mysql.user table(field password_expired='N') not to expire the password.
best easy solution:
[PATH MYSQL]/bin/mysql -u root
[Enter password]
SET GLOBAL default_password_lifetime = 0;
and then works fine.
This work for me:
Source: https://www.diariodeunprogramador.net/fallo-al-conectar-mysql-your-password-expired/
Login as root:
mysql -u root -p
and then you deactivate the automatic expiration of passwords of all the users:
SET GLOBAL default_password_lifetime = 0;
On DBeaver, Edit Connection -> Driver Properties -> disable disconnectOnExpiredPasswords:
Reconnect and:
And execute:
SET PASSWORD FOR 'user-name'#'localhost' = PASSWORD('NEW_USER_PASSWORD');
FLUSH PRIVILEGES;
The password expiration is a new feature in MySQL 5.6 or 5.7.
The answer is clear: Use a client which is capable of expired password changing (I think Sequel Pro can do it).
MySQLi library obviously isnt able to change the expired password.
If you have limited access to localhost and you only have a console client, the standard mysql client can do it.
Open MySQL console and type SET PASSWORD = 'your password';
and then press ENTER Key which will set your defined password for user root.
You can only write SET PASSWORD = '';
which will set password as blank for root user.
I did something like this.
UPDATE mysql.user SET authentication_string = PASSWORD(''), password_expired = 'N' WHERE User = 'root' AND Host = 'localhost';
For MySQL 8.0 +, if you get this error,
*Your password has expired. To log in you must change it using a client that
supports expired passwords.*
you need use current user , to open mysql terminal, then use
SET PASSWORD ='123456'; To get a new password 123456 for current user;
Don't use SET PASSWORD = PASSWORD('123456'); This one have been deprecated in MySQL 8.0+;
Just open MySQL Workbench and choose [Instance] Startup/Shutdown and click on start server.
It worked for me
This should be dead simple, but I cannot get it to work for the life of me.
I'm just trying to connect remotely to my MySQL server.
Connecting as:
mysql -u root -h localhost -p
works fine, but trying:
mysql -u root -h 'any ip address here' -p
fails with the error:
ERROR 1130 (00000): Host 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL server
In the mysql.user table, there is exactly the same entry for user 'root' with host 'localhost' as another with host '%'.
I'm at my wits' end and have no idea how to proceed.
Any ideas are welcome.
Possibly a security precaution. You could try adding a new administrator account:
mysql> CREATE USER 'monty'#'localhost' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'#'localhost'
-> WITH GRANT OPTION;
mysql> CREATE USER 'monty'#'%' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'#'%'
-> WITH GRANT OPTION;
Although as Pascal and others have noted it's not a great idea to have a user with this kind of access open to any IP. If you need an administrative user, use root, and leave it on localhost. For any other action specify exactly the privileges you need and limit the accessibility of the user as Pascal has suggest below.
Edit:
From the MySQL FAQ:
If you cannot figure out why you get
Access denied, remove from the user
table all entries that have Host
values containing wildcards (entries
that contain '%' or '_' characters). A
very common error is to insert a new
entry with Host='%' and
User='some_user', thinking that this
allows you to specify localhost to
connect from the same machine. The
reason that this does not work is that
the default privileges include an
entry with Host='localhost' and
User=''. Because that entry has a Host
value 'localhost' that is more
specific than '%', it is used in
preference to the new entry when
connecting from localhost! The correct
procedure is to insert a second entry
with Host='localhost' and
User='some_user', or to delete the
entry with Host='localhost' and
User=''. After deleting the entry,
remember to issue a FLUSH PRIVILEGES
statement to reload the grant tables.
See also Section 5.4.4, “Access
Control, Stage 1: Connection
Verification”.
One has to create a new MySQL User and assign privileges as below in Query prompt via phpMyAdmin or command prompt:
CREATE USER 'username'#'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'#'localhost' WITH GRANT OPTION;
CREATE USER 'username'#'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'#'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Once done with all four queries, it should connect with username / password
My error message was similar and said 'Host XXX is not allowed to connect to this MySQL server' even though I was using root. Here's how to make sure that root has the correct permissions.
My setup:
Ubuntu 14.04 LTS
MySQL v5.5.37
Solution
Open up the file under etc/mysql/my.cnf
Check for:
port (by default this is port = 3306)
bind-address (by default this is bind-address = 127.0.0.1; if you want to open to all then just comment out this line. For my example, I'll say the actual server is on 10.1.1.7)
Now access the MySQL Database on your actual server (say your remote address is 123.123.123.123 at port 3306 as user root and I want to change permissions on database 'dataentry'. Remember to change the IP Address, Port, and database name to your settings)
mysql -u root -p
Enter password: <enter password>
mysql>GRANT ALL ON *.* to root#'123.123.123.123' IDENTIFIED BY 'put-your-password';
mysql>FLUSH PRIVILEGES;
mysql>exit
sudo service mysqld restart
You should now be able to remote connect to your database. For example, I'm using MySQL Workbench and putting in 'Hostname:10.1.1.7', 'Port:3306', 'Username:root'
Just perform the following steps:
Connect to MySQL (via localhost)
mysql -uroot -p
If the MySQL server is running in Kubernetes (K8s) and being accessed via a NodePort
kubectl exec -it [pod-name] -- /bin/bash
mysql -uroot -p
Create user
CREATE USER 'user'#'%' IDENTIFIED BY 'password';
Grant permissions
GRANT ALL PRIVILEGES ON *.* TO 'user'#'%' WITH GRANT OPTION;
Flush privileges
FLUSH PRIVILEGES;
You need to grant access to the user from any hostname.
This is how you add new privilege from phpmyadmin
Goto Privileges > Add a new User
Select Any Host for the desired username
Simple way:
Grant All Privileges ON *.* to 'USER_NAME'#'%' Identified By 'YOUR_PASSWORD';
then
FLUSH PRIVILEGES;
done!
The message *Host ''xxx.xx.xxx.xxx'' is not allowed to connect to this MySQL server is a reply from the MySQL server to the MySQL client. Notice how its returning the IP address and not the hostname.
If you're trying to connect with mysql -h<hostname> -u<somebody> -p and it returns this message with the IP address, then the MySQL server isn't able to do a reverse lookup on the client. This is critical because thats how it maps the MySQL client to the grants.
Make sure you can do an nslookup <mysqlclient> FROM the MySQL server. If that doesn't work, then there's no entry in the DNS server. Alternatively, you can put an entry in the MySQL server's HOSTS file (<ipaddress> <fullyqualifiedhostname> <hostname> <- The order here might matter).
An entry in my server's host file allowing a reverse lookup of the MySQL client solved this very problem.
This working for any future remote mysql connection !
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
Navigate to the line that begins with the bind-address directive. It should look like this:
bind-address = 0.0.0.0
Login to your mysql as root terminal
mysql -u root -p
-- root password
CREATE USER 'username'#'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'#'localhost' WITH GRANT OPTION;
CREATE USER 'username'#'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'#'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;
finally Grant that machine exclusive permission to connect to the database remotely with the following command.
sudo ufw allow from remote_IP_address to any port 3306
If you modify the grant tables manually (using INSERT, UPDATE, etc.), you should execute
a FLUSH PRIVILEGES statement to tell the server to reload the grant tables.
PS: I wouldn't recommend to allow any host to connect for any user (especially not the root use). If you are using mysql for a client/server application, prefer a subnet address. If you are using mysql with a web server or application server, use specific IPs.
Just use the interface provided by MySql's GUI Tool (SQLyog):
Click on User manager:
Now, if you want to grant access FOR ANY OTHER REMOTE PC, just make sure that, just like in the underneath picture, the Host field value is % (which is the wildcard)
Most of the answers here show you creating users with two host values: one for localhost, and one for %.
Please note that except for a built-in localhost user like root, you don't need to do this. If you simply want to make a new user that can log in from anywhere, you can use
CREATE USER 'myuser'#'%' IDENTIFIED BY 'mypassword';
GRANT <whatever privileges are appropriate> ON <relevant tables> TO myuser;
and it will work just fine. (As others have mentioned, it's a terrible idea to grant administrative privileges to a user from any domain.)
If you are using MySQL WorkBench, you can achieve this easily:
From the menu, select Server -> Users And Privileges
On the lower left, click on "Add account"
Fill the form with username, host matching (% means every host) and the password
Click on "Apply" on the lower right
After this you are good to go. Then, if you want to refine your configuration, you can use the "Administrative Roles" tab to set the command that can be used by the user (SELECT, ALTER etc etc) and the "Schema privileges" tab to restrict the user interaction to specific schemas.
Well, nothing of the above answer worked for me. After a lot of research, I found a solution. Though I may be late this may help others in future.
Login to your SQL server from a terminal
mysql -u root -p
-- root password
GRANT ALL ON *.* to root#'XX.XXX.XXX.XX' IDENTIFIED BY 'password';
This should solve the permission issue.
Happy coding!!
simple way is to login to phpmyadmin with root account , there goto mysql database and select user table , there edit root account and in host field add % wild card . and then through ssh flush privileges
FLUSH PRIVILEGES;
If this is a recent mysql install, then before changing anything else, try simply to execute this command and then try again:
flush privileges;
This alone fixes the issue for me on Ubuntu 16.04, mysql 5.7.20. YMMV.
Just find a better way to do that from your hosting control panel (I'm using DirectAdmin here)
simply go to the target server DB in your control panel, in my case:
MySQL management -> select your DB -> you will find: "Access Hosts", simply add your remote host here and its working now!
I guess there is a similar option on other C.panels like plesk, etc..
I'm hope it was helpful to you too.
If you happen to be running on Windows; A simple solution is to run the MySQL server instance configuration wizard. It is in your MYSQL group in the start menu. On the second from last screen click the box that says "allow root access from remote machines".
CREATE USER 'username'#'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
this error because no password to the root , and this Maybe occurred with you when you trying to connect from outside .
If you have WAMP Server + Windows 10 and you are using it for development than Right Click on Wamp Icon => Wamp Settings => Check Allow Virtual Hosts other than 127*
I was also facing same issue, It resolved in 2 min for me i just white list ip through cpanel
Suppose you are trying to connect database of server B from server A.
Go to Server B Cpanel->Remote MySQL-> enter Server A IP Address and That's it.
Well what you can do is just open mysql.cfg file and you have to change Bind-address to this
bind-address = 127.0.0.1
and then Restart mysql and you will able to connect that server to this.
Look this you can have idea form that.
this is real sol
This answer might help someone...
All these answers didnt help, then I realised I forgot to check one crucial thing.. The port :)
I have mysql running in a docker container running on a different port. I was pointing to my host machine on port 3306, which I have a mysql server running on. My container exposes the server on port 33060. So all this time, i was looking at the wrong server! doh!
This working for DirectAdmin;
Go to your DirectAdmin.
Go to your MySQL Management.
Select your database.
Under your Accesse Host tab, there is a field.
You should fill this field by xxx.xx.xxx.xx.
Click on Add Host.
Finished. Now you can access to this DB by your your_database_username & your_database_password.
So Simple!
CPANEL solution
Go to Cpanel, look for Remote MySQL.
Add the the IP in the input field:
Host (% wildcard is allowed)
Comment to remember what IP that is.
That was it for me.
1. From a terminal, connect you to your MySQL running container
docker exec -it your_container_name_or_id bash
2. In your container, connect you to the MySQL database
mysql -u your_user -p
enter your password to connect to database.
3. execute this SQL script to list all existing database users:
SELECT host, user FROM mysql.user;
The result will be some thing like below:
host
user
127.0.0.1
root
::1
root
localhost
mysql.sys
localhost
root
you should add a new row:
host
user
%
root
CREATE USER 'username'#'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'#'%' WITH GRANT OPTION;
Some tips:
list privileges using show grants;
create a VPN and just add the ip of the tunnel
Problem: root#localhost is unable to connect to a fresh installation of mysql-community-server on openSUSE 42.2-1.150.x86_64.
Mysql refuses connections - period.
Solution:
$ ls -l /var/lib/mysql/mysql/user.*
-rw-rw---- 1 mysql mysql 0 Apr 29 19:44 /var/lib/mysql/mysql/user.MYD
-rw-rw---- 1 mysql mysql 1024 Apr 29 19:44 /var/lib/mysql/mysql/user.MYI
-rw-rw---- 1 mysql mysql 10684 Apr 29 19:44 /var/lib/mysql/mysql/user.frm
File user.MYD has 0 size (really ?!).
I copied all 3 files from another working system.
$ /usr/sbin/rcmysql stop
$ cd /var/lib/mysql/mysql/
$ scp root#othersytem:/var/lib/mysql/mysql/user.* ./
$ /usr/sbin/rcmysql start
$ cd -
$ mysql -u root -p
I was able to log in. Then, it was just a matter of re-applying all schema privileges.
Also, if you disabled IPv6, re-enable it temporary so that root#::1 account can also work.
if you are trying to execute mysql query withouth defining connectionstring, you will get this error.
Probably you forgat to define connection string before execution. have you check this out?
(sorry for bad english)
All of the answers here didn't work in my case so I guest this may help other users in the future. This can also be a problem in our code, not just in MySQL alone.
If you are using VB.NET
Instead of this code:
Dim server As String = My.Settings.DB_Server
Dim username As String = My.Settings.DB_Username
Dim password As String = My.Settings.DB_Password
Dim database As String = My.Settings.DB_Database
MysqlConn.ConnectionString = "server=" & server & ";" _
& "user id=" & username & ";" _
& "password=" & password & ";" _
& "database=" & database
MysqlConn = New MySqlConnection()
You need to move MysqlConn = New MySqlConnection() on the first line. So it would be like this
MysqlConn = New MySqlConnection()
Dim server As String = My.Settings.DB_Server
Dim username As String = My.Settings.DB_Username
Dim password As String = My.Settings.DB_Password
Dim database As String = My.Settings.DB_Database
MysqlConn.ConnectionString = "server=" & server & ";" _
& "user id=" & username & ";" _
& "password=" & password & ";" _
& "database=" & database