Related
I am connecting MySQL - 8.0 with MySQL Workbench and getting the below error:
Authentication plugin 'caching_sha2_password' cannot be loaded:
dlopen(/usr/local/mysql/lib/plugin/caching_sha2_password.so, 2): image
not found
I have tried with other client tool as well.
Any solution for this?
you can change the encryption of the password like this.
ALTER USER 'yourusername'#'localhost' IDENTIFIED WITH mysql_native_password BY 'youpassword';
Note: For MAC OS
Open MySQL from System Preferences > Initialize Database >
Type your new password.
Choose 'Use legacy password'
Start the Server again.
Now connect the MySQL Workbench
For Windows 10:
Open the command prompt:
cd "C:\Program Files\MySQL\MySQL Server 8.0\bin"
C:\Program Files\MySQL\MySQL Server 8.0\bin> mysql -u root -p
Enter password: *********
mysql> ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'newrootpassword';
Query OK, 0 rows affected (0.10 sec)
mysql> exit
Alternatively, you can change the my.ini configuration as the following:
[mysqld]
default_authentication_plugin=mysql_native_password
Restart the MySQL Server and open the Workbench again.
I had the same problem, but the answer by Aman Aggarwal didn't work for me with a Docker container running mysql 8.X.
I loged in the container
docker exec -it CONTAINER_ID bash
then log into mysql as root
mysql --user=root --password
Enter the password for root (Default is 'root')
Finally Run:
ALTER USER 'username' IDENTIFIED WITH mysql_native_password BY 'password';
You're all set.
You can change the encryption of the user's password by altering the user with below Alter command :
ALTER USER 'username'#'ip_address' IDENTIFIED WITH mysql_native_password BY
'password';
OR
We can avoid this error by make it work with old password plugin:
First change the authentication plugin in my.cnf file for Linux / my.ini file in Windows:
[mysqld]
default_authentication_plugin=mysql_native_password
Restart the mysql server to take the changes in affect and try connecting via MySQL with any mysql client.
If still unable to connect and getting the below error:
Unable to load plugin 'caching_sha2_password'
It means your user needs the above plugin. So try creating new user with create user or grant command after changing default plugin. then new user need the native plugin and you will able to connect MySQL.
Thanks
Currently (on 2018/04/23), you need to download a development release. The GA ones do not work.
I was not able to connect with the latest GA version (6.3.10).
It worked with mysql-workbench-community-8.0.11-rc-winx64.msi (from https://dev.mysql.com/downloads/workbench/, tab Development Releases).
Ok, wasted a lot of time on this so here is a summary as of 19 March 2019
If you are specifically trying to use a Docker image with MySql 8+, and then use SequelPro to access your database(s) running on that docker container, you are out of luck.
See the sequelpro issue 2699
My setup is sequelpro 1.1.2 using docker desktop 2.0.3.0 (mac - mojave), and tried using mysql:latest (v8.0.15).
As others have reported, using mysql 5.7 works with nothing required:
docker run -p 3306:3306 --name mysql1 -e MYSQL_ROOT_PASSWORD=secret -d mysql:5.7
Of course, it is possible to use MySql 8+ on docker, and in that situation (if needed), other answers provided here for caching_sha2_password type issues do work. But sequelpro is a NO GO with MySql 8+
Finally, I abandoned sequelpro (a trusted friend from back in 2013-2014) and instead installed DBeaver. Everything worked out of the box. For docker, I used:
docker run -p 3306:3306 --name mysql1 -e MYSQL_ROOT_PASSWORD=secret -d mysql:latest --default-authentication-plugin=mysql_native_password
You can quickly peek at the mysql databases using:
docker exec -it mysql1 bash
mysql -u root -p
show databases;
I was installing MySQL on my Windows 10 PC using "MySQL Web Installer" and was facing the same issue while trying to connect using MySQL workbench. I fixed the issue by reconfiguring the server form the Installer window.
Clicking on the "Reconfigure" option it will allow to reconfigure the server. Click on "Next" until you reach "Authentication Method".
Once on this tab, use the second option "Use Legacy Authentication Method (Retain MySQL 5.x Compatibility)".
Keep everything else as is and that is how I solved my issue.
Note: For Linux (Debian, Ubuntu, Mint)
I got this error:
MySQL Error Message: Plugin caching_sha2_password could not be loaded: /usr/lib/x86_64-linux-gnu/mariadb19/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory
I solved it with these steps:
Enter on mysql console: $ mysql -u root -p, if you don't have a password for root user, then:
Use mysql db: mysql> use mysql;
Alter your user for solve the problem: mysql> ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Exit... mysql> quit;
Done!
like this?
docker run -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -d mysql --default-authentication-plugin=mysql_native_password
mysql -uroot --protocol tcp
Try in PWD
https://github.com/GitHub30/docs/blob/change-default_authentication_plugin/mysql/stack.yml
or You shoud use MySQL Workbench 8.0.11.
Open MySQL Command Line Client
Create a new user with a new pass
Considering an example of a path to a bin folder on top, here's the code you need to run in the command prompt, line by line:
cd C:\Program Files\MySQL\MySQL Server 5.7\bin
MySQL -u root -p
current password...***
CREATE USER 'nativeuser'#'localhost'
IDENTIFIED WITH mysql_native_password BY 'new_password';
Then, you can access Workbench again (you should be able to do that after creating a new localhost connection and using the new credentials to start using the program).
Set up a new local host connection with the user name mentioned above (native user), login using the password (new_password)
Courtesy: UDEMY FAQs answered by Career365 Team
For Windows 10,
Modify my.ini file in C:\ProgramData\MySQL\MySQL Server 8.0\
[mysqld]
default_authentication_plugin=mysql_native_password
Restart the MySQL Service.
Login to MySQL on the command line, and execute the following commands in MySQL:
Create a new user.
CREATE USER 'user'#'localhost' IDENTIFIED BY 'password';
Grant all privileges.
GRANT ALL PRIVILEGES ON * .* TO 'user'#'localhost';
Open MySQL workbench, and open a new connection using the new user credentials.
I was facing the same issue and this worked.
Although this shouldn't be a real
solution, it does work locally if you are stuck
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY '';
This is my databdase definition in my docker-compose:
dataBase:
image: mysql:8.0
volumes:
- db_data:/var/lib/mysql
networks:
z-net:
ipv4_address: 172.26.0.2
restart: always
entrypoint: ['docker-entrypoint.sh', '--default-authentication-plugin=mysql_native_password']
environment:
MYSQL_ROOT_PASSWORD: supersecret
MYSQL_DATABASE: zdb
MYSQL_USER: zuser
MYSQL_PASSWORD: zpass
ports:
- "3333:3306"
The relevant line there is entrypoint.
After build and up it, you can test it with:
$ mysql -u zuser -pzpass --host=172.26.0.2 zdb -e "select 1;"
Warning: Using a password on the command line interface can be insecure.
+---+
| 1 |
+---+
| 1 |
+---+
For those using Docker or Docker Compose, I experienced this error because I didn't set my MySQL image version. Docker will automatically attempt to get the latest version which is 8.
I set MySQL to 5.7 and rebuilt the image and it worked as normal:
version: '2'
services:
db:
image: mysql:5.7
I found that
ALTER USER 'username'#'ip_address' IDENTIFIED WITH mysql_native_password BY 'password';
didn't work by itself. I also needed to set
[mysqld]
default_authentication_plugin=mysql_native_password
in /etc/mysql/mysql.conf.d/mysqld.cnf
on Ubuntu 18.04 running PHP 7.0
Here is the solution which worked for me after MySQL 8.0 Installation on Windows 10.
Suppose MySQL username is root and password is admin
Open command prompt and enter the following commands:
cd C:\Program Files\MySQL\MySQL Server 8.0\bin
mysql_upgrade -uroot -padmin
mysql -uroot -padmin
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY
'admin'
If you are getting this error on GitLab CI like me:
Just change from latest to 5.7 version ;)
# .gitlab-ci.yml
rspec:
services:
# - mysql:latest (I'm using latest version and it causes error)
- mysql:5.7 #(then I've changed to this specific version and fix!)
Open my sql command promt:
then enter mysql password
finally use:
ALTER USER 'username'#'ip_address' IDENTIFIED WITH mysql_native_password BY 'password';
refer:https://stackoverflow.com/a/49228443/6097074
Thanks.
For me this started happening because on a project, I was using Docker image mysql:latest (which was version 5, and which was working fine), and during a later build, the latest version was switched to version 8, and stopped working. I changed my image to mysql:5 and I was no longer getting this error.
This error comes up when the tool being used is not compatible with MySQL8, try updating to the latest version of MySQL Workbench for MySQL8
If you still want to use the new authentication method, the proper solution is to install the mariadb-connector-c package. For Alpine, run:
apk add mariadb-connector-c
This will add the missing caching_sha2_password.so library into /usr/lib/mariadb/plugin/caching_sha2_password.so.
Almost like answers above but may be in simple queries, I was getting this error in my spring boot application along with hibernate after MySQL upgrade. We created a new user by running the queries below against our DB. I believe this is a temp work around to use sha256_password instead of latest and good authentication caching_sha2_password.
CREATE USER 'username'#'localhost' IDENTIFIED WITH mysql_native_password BY 'pa$$word';
GRANT ALL PRIVILEGES ON * .* TO 'username'#'localhost';
MySQLWorkbench 8.0.11 for macOS addresses this.
I can establish connection with root password protected mysql instance running in docker.
If you are trying to connect to a MySQL server from a text-based MySQL client from another computer (be it Docker or not)
Most answers here involve connecting from a desktop client, or ask you to switch to an older authentication method. If you're connecting it with the MySQL client (text-based), I made it work with a Debian Buster in a Docker container.
Say you have the apt system and wget set up, do the following:
sudo apt-get update
sudo apt-get install lsb-release -y
Download a Debian package which update apt sources for you from the MySQL web site.
sudo dpkg -i mysql-apt-config_0.8.13-1_all.deb and select the options you want. In my case I only need MySQL Tools & Connectors to be enabled.
sudo apt-get update
sudo apt-get install mysql-client -y
Done. You can now run the new MySQL client and connect with the new authentication method.
The below solution worked for me
Go to Mysql Workbench -> Server-> Users and Privileges
1.Click Add Account
2.Under Login Tab provide new details and make sure to choose the Authentication Type as standard and choose respective administrative roles and Schema Privileges
Actually MySql allows two type of authentication at the time of installation.
Password Encryption
Legacy Encryption
Read Here
So by checking legacy authentication the issue was resolved.
Try using legacy password while downloading and installing MySql, that helped me.
Or follow the method posted by Santhosh Shivan for Mac OS.
Just downloaded the latest mysqlworkbench which is compatible with the latest encryption:
https://downloads.mysql.com/archives/workbench/
Note: On Mac big Sur, the latest two versions: 8.0.22 and 8.0.23 are buggy and do not work.
Use 8.0.21 until these are fixed
I run docker in M1 (arm64), the direct way of changing in the docker bash does not work for me. Instead, I change the mysql image to be
mysql:8.0.26
and the platform is set as
linux/x86_64
and add default_authentication_plugin=mysql_native_password to my.cnf
Then, you rebuild your container.
I am connecting MySQL - 8.0 with MySQL Workbench and getting the below error:
Authentication plugin 'caching_sha2_password' cannot be loaded:
dlopen(/usr/local/mysql/lib/plugin/caching_sha2_password.so, 2): image
not found
I have tried with other client tool as well.
Any solution for this?
you can change the encryption of the password like this.
ALTER USER 'yourusername'#'localhost' IDENTIFIED WITH mysql_native_password BY 'youpassword';
Note: For MAC OS
Open MySQL from System Preferences > Initialize Database >
Type your new password.
Choose 'Use legacy password'
Start the Server again.
Now connect the MySQL Workbench
For Windows 10:
Open the command prompt:
cd "C:\Program Files\MySQL\MySQL Server 8.0\bin"
C:\Program Files\MySQL\MySQL Server 8.0\bin> mysql -u root -p
Enter password: *********
mysql> ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'newrootpassword';
Query OK, 0 rows affected (0.10 sec)
mysql> exit
Alternatively, you can change the my.ini configuration as the following:
[mysqld]
default_authentication_plugin=mysql_native_password
Restart the MySQL Server and open the Workbench again.
I had the same problem, but the answer by Aman Aggarwal didn't work for me with a Docker container running mysql 8.X.
I loged in the container
docker exec -it CONTAINER_ID bash
then log into mysql as root
mysql --user=root --password
Enter the password for root (Default is 'root')
Finally Run:
ALTER USER 'username' IDENTIFIED WITH mysql_native_password BY 'password';
You're all set.
You can change the encryption of the user's password by altering the user with below Alter command :
ALTER USER 'username'#'ip_address' IDENTIFIED WITH mysql_native_password BY
'password';
OR
We can avoid this error by make it work with old password plugin:
First change the authentication plugin in my.cnf file for Linux / my.ini file in Windows:
[mysqld]
default_authentication_plugin=mysql_native_password
Restart the mysql server to take the changes in affect and try connecting via MySQL with any mysql client.
If still unable to connect and getting the below error:
Unable to load plugin 'caching_sha2_password'
It means your user needs the above plugin. So try creating new user with create user or grant command after changing default plugin. then new user need the native plugin and you will able to connect MySQL.
Thanks
Currently (on 2018/04/23), you need to download a development release. The GA ones do not work.
I was not able to connect with the latest GA version (6.3.10).
It worked with mysql-workbench-community-8.0.11-rc-winx64.msi (from https://dev.mysql.com/downloads/workbench/, tab Development Releases).
Ok, wasted a lot of time on this so here is a summary as of 19 March 2019
If you are specifically trying to use a Docker image with MySql 8+, and then use SequelPro to access your database(s) running on that docker container, you are out of luck.
See the sequelpro issue 2699
My setup is sequelpro 1.1.2 using docker desktop 2.0.3.0 (mac - mojave), and tried using mysql:latest (v8.0.15).
As others have reported, using mysql 5.7 works with nothing required:
docker run -p 3306:3306 --name mysql1 -e MYSQL_ROOT_PASSWORD=secret -d mysql:5.7
Of course, it is possible to use MySql 8+ on docker, and in that situation (if needed), other answers provided here for caching_sha2_password type issues do work. But sequelpro is a NO GO with MySql 8+
Finally, I abandoned sequelpro (a trusted friend from back in 2013-2014) and instead installed DBeaver. Everything worked out of the box. For docker, I used:
docker run -p 3306:3306 --name mysql1 -e MYSQL_ROOT_PASSWORD=secret -d mysql:latest --default-authentication-plugin=mysql_native_password
You can quickly peek at the mysql databases using:
docker exec -it mysql1 bash
mysql -u root -p
show databases;
I was installing MySQL on my Windows 10 PC using "MySQL Web Installer" and was facing the same issue while trying to connect using MySQL workbench. I fixed the issue by reconfiguring the server form the Installer window.
Clicking on the "Reconfigure" option it will allow to reconfigure the server. Click on "Next" until you reach "Authentication Method".
Once on this tab, use the second option "Use Legacy Authentication Method (Retain MySQL 5.x Compatibility)".
Keep everything else as is and that is how I solved my issue.
Note: For Linux (Debian, Ubuntu, Mint)
I got this error:
MySQL Error Message: Plugin caching_sha2_password could not be loaded: /usr/lib/x86_64-linux-gnu/mariadb19/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory
I solved it with these steps:
Enter on mysql console: $ mysql -u root -p, if you don't have a password for root user, then:
Use mysql db: mysql> use mysql;
Alter your user for solve the problem: mysql> ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Exit... mysql> quit;
Done!
like this?
docker run -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=yes -d mysql --default-authentication-plugin=mysql_native_password
mysql -uroot --protocol tcp
Try in PWD
https://github.com/GitHub30/docs/blob/change-default_authentication_plugin/mysql/stack.yml
or You shoud use MySQL Workbench 8.0.11.
Open MySQL Command Line Client
Create a new user with a new pass
Considering an example of a path to a bin folder on top, here's the code you need to run in the command prompt, line by line:
cd C:\Program Files\MySQL\MySQL Server 5.7\bin
MySQL -u root -p
current password...***
CREATE USER 'nativeuser'#'localhost'
IDENTIFIED WITH mysql_native_password BY 'new_password';
Then, you can access Workbench again (you should be able to do that after creating a new localhost connection and using the new credentials to start using the program).
Set up a new local host connection with the user name mentioned above (native user), login using the password (new_password)
Courtesy: UDEMY FAQs answered by Career365 Team
For Windows 10,
Modify my.ini file in C:\ProgramData\MySQL\MySQL Server 8.0\
[mysqld]
default_authentication_plugin=mysql_native_password
Restart the MySQL Service.
Login to MySQL on the command line, and execute the following commands in MySQL:
Create a new user.
CREATE USER 'user'#'localhost' IDENTIFIED BY 'password';
Grant all privileges.
GRANT ALL PRIVILEGES ON * .* TO 'user'#'localhost';
Open MySQL workbench, and open a new connection using the new user credentials.
I was facing the same issue and this worked.
Although this shouldn't be a real
solution, it does work locally if you are stuck
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY '';
This is my databdase definition in my docker-compose:
dataBase:
image: mysql:8.0
volumes:
- db_data:/var/lib/mysql
networks:
z-net:
ipv4_address: 172.26.0.2
restart: always
entrypoint: ['docker-entrypoint.sh', '--default-authentication-plugin=mysql_native_password']
environment:
MYSQL_ROOT_PASSWORD: supersecret
MYSQL_DATABASE: zdb
MYSQL_USER: zuser
MYSQL_PASSWORD: zpass
ports:
- "3333:3306"
The relevant line there is entrypoint.
After build and up it, you can test it with:
$ mysql -u zuser -pzpass --host=172.26.0.2 zdb -e "select 1;"
Warning: Using a password on the command line interface can be insecure.
+---+
| 1 |
+---+
| 1 |
+---+
For those using Docker or Docker Compose, I experienced this error because I didn't set my MySQL image version. Docker will automatically attempt to get the latest version which is 8.
I set MySQL to 5.7 and rebuilt the image and it worked as normal:
version: '2'
services:
db:
image: mysql:5.7
I found that
ALTER USER 'username'#'ip_address' IDENTIFIED WITH mysql_native_password BY 'password';
didn't work by itself. I also needed to set
[mysqld]
default_authentication_plugin=mysql_native_password
in /etc/mysql/mysql.conf.d/mysqld.cnf
on Ubuntu 18.04 running PHP 7.0
Here is the solution which worked for me after MySQL 8.0 Installation on Windows 10.
Suppose MySQL username is root and password is admin
Open command prompt and enter the following commands:
cd C:\Program Files\MySQL\MySQL Server 8.0\bin
mysql_upgrade -uroot -padmin
mysql -uroot -padmin
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY
'admin'
If you are getting this error on GitLab CI like me:
Just change from latest to 5.7 version ;)
# .gitlab-ci.yml
rspec:
services:
# - mysql:latest (I'm using latest version and it causes error)
- mysql:5.7 #(then I've changed to this specific version and fix!)
Open my sql command promt:
then enter mysql password
finally use:
ALTER USER 'username'#'ip_address' IDENTIFIED WITH mysql_native_password BY 'password';
refer:https://stackoverflow.com/a/49228443/6097074
Thanks.
For me this started happening because on a project, I was using Docker image mysql:latest (which was version 5, and which was working fine), and during a later build, the latest version was switched to version 8, and stopped working. I changed my image to mysql:5 and I was no longer getting this error.
This error comes up when the tool being used is not compatible with MySQL8, try updating to the latest version of MySQL Workbench for MySQL8
If you still want to use the new authentication method, the proper solution is to install the mariadb-connector-c package. For Alpine, run:
apk add mariadb-connector-c
This will add the missing caching_sha2_password.so library into /usr/lib/mariadb/plugin/caching_sha2_password.so.
Almost like answers above but may be in simple queries, I was getting this error in my spring boot application along with hibernate after MySQL upgrade. We created a new user by running the queries below against our DB. I believe this is a temp work around to use sha256_password instead of latest and good authentication caching_sha2_password.
CREATE USER 'username'#'localhost' IDENTIFIED WITH mysql_native_password BY 'pa$$word';
GRANT ALL PRIVILEGES ON * .* TO 'username'#'localhost';
MySQLWorkbench 8.0.11 for macOS addresses this.
I can establish connection with root password protected mysql instance running in docker.
If you are trying to connect to a MySQL server from a text-based MySQL client from another computer (be it Docker or not)
Most answers here involve connecting from a desktop client, or ask you to switch to an older authentication method. If you're connecting it with the MySQL client (text-based), I made it work with a Debian Buster in a Docker container.
Say you have the apt system and wget set up, do the following:
sudo apt-get update
sudo apt-get install lsb-release -y
Download a Debian package which update apt sources for you from the MySQL web site.
sudo dpkg -i mysql-apt-config_0.8.13-1_all.deb and select the options you want. In my case I only need MySQL Tools & Connectors to be enabled.
sudo apt-get update
sudo apt-get install mysql-client -y
Done. You can now run the new MySQL client and connect with the new authentication method.
The below solution worked for me
Go to Mysql Workbench -> Server-> Users and Privileges
1.Click Add Account
2.Under Login Tab provide new details and make sure to choose the Authentication Type as standard and choose respective administrative roles and Schema Privileges
Actually MySql allows two type of authentication at the time of installation.
Password Encryption
Legacy Encryption
Read Here
So by checking legacy authentication the issue was resolved.
Try using legacy password while downloading and installing MySql, that helped me.
Or follow the method posted by Santhosh Shivan for Mac OS.
Just downloaded the latest mysqlworkbench which is compatible with the latest encryption:
https://downloads.mysql.com/archives/workbench/
Note: On Mac big Sur, the latest two versions: 8.0.22 and 8.0.23 are buggy and do not work.
Use 8.0.21 until these are fixed
I run docker in M1 (arm64), the direct way of changing in the docker bash does not work for me. Instead, I change the mysql image to be
mysql:8.0.26
and the platform is set as
linux/x86_64
and add default_authentication_plugin=mysql_native_password to my.cnf
Then, you rebuild your container.
I have just installed mySQL 5.1.55 on a Linux box, and it seems to be ok
# /usr/local/mysql/bin/mysql_install_db
Installing MySQL system tables...
160606 21:46:25 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
OK
Filling help tables...
160606 21:46:26 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql-5.1.55/bin/mysqladmin -u root password 'new-password'
Alternatively you can run:
/usr/local/mysql-5.1.55/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr/local/mysql-5.1.55 ; /usr/local/mysql-5.1.55/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/mysql-5.1.55/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/local/mysql-5.1.55/bin/mysqlbug script!
However, if I run
# /usr/local/mysql-5.1.55/bin/mysqladmin -u root password foo
I get this error message:
/usr/local/mysql-5.1.55/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'#'localhost' (using password: NO)'
If I run:
# /usr/local/mysql-5.1.55/bin/mysql -u root -p
I am not able to figure out which the password is :-S
Any help is welcome. Thank you very much.
If you have installed mysql without running
> mysql_secure_installation
script there should be no password at all. Just type
> mysql
and see what happens. If that fails you can still set a new root password following the mysql manual
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
Then I do
cd ~/Desktop/iPDC-v1.3.1/DBServer-1.1
mysql -uroot -proot <"Db.sql"
I ended up with the following error message.
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
How may I fix it and continue?
Note: For MySQL 5.7+, please see the answer from Lahiru to this question. That contains more current information.
For MySQL < 5.7:
The default root password is blank (i.e., an empty string), not root. So you can just log in as:
mysql -u root
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.
I was recently faced with the same problem, but in my case, I remember my password quite alright, but it kept on giving me the same error. I tried so many solutions, but still none helped. Then I tried this:
mysql -u root -p
After which it asks you for a password like this
Enter password:
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.
You have to reset the password! Steps for Mac OS X (tested and working) and Ubuntu:
Stop MySQL using
sudo service mysql stop
or
sudo /usr/local/mysql/support-files/mysql.server stop
Start it in safe mode:
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';
Start MySQL using:
sudo service mysql start
or
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';
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
Start the database without loading the grant tables or enabling networking:
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
Make MySQL service directory.
sudo mkdir /var/run/mysqld
Give MySQL user permission to write to the service directory.
sudo chown mysql: /var/run/mysqld
Run the same command in step 2 to run MySQL in background.
Run mysql -u root. You will get the MySQL console without entering a password.
Run these commands
FLUSH PRIVILEGES;
For MySQL 5.7.6 and newer
ALTER USER 'root'#'localhost' IDENTIFIED BY 'new_password';
For MySQL 5.7.5 and older
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('new_password');
If the ALTER USER command doesn't work use:
UPDATE mysql.user SET authentication_string = PASSWORD('new_password') WHERE User = 'root' AND Host = 'localhost';
Now exit
To stop the instance started manually:
sudo kill `cat /var/run/mysqld/mysqld.pid`
Restart MySQL
sudo systemctl start mysql
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!';
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;
Stop the MySQL server:
/etc/init.d/mysql stop
Start the MySQL server and test it:
mysql -u root -p
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
I came across this very annoying problem and found many answers that did not work. The best solution I came across was to completely uninstall MySQL and reinstall it. On reinstall you set a root password and this fixed the problem.
sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-core-5.5 mysql-client-core-5.5
sudo rm -rf /etc/mysql /var/lib/mysql
sudo apt-get autoremove
sudo apt-get autoclean
I found this code elsewhere, so I don't take any credit for it. But it works. To install MySQL after uninstalling it, I think DigitalOcean has a good tutorial on it. Checkout my gist for this.
How to install MySQL on Ubuntu (which works)
I am using Ubuntu 16.04 (Xenial Xerus) and installed MySQL 5.7.
I had the same issue
Login denied for root user.
I tried the below steps:
dpkg --get-selections | grep mysql (to get the version of MySQL).
dpkg-reconfigure mysql-server-5.7
mysql -u root -p
Without -p that doesn't prompt you to ask password. Once you are in, you can create a user with a password by following steps:
CREATE USER 'your_new_username'#'your-hostname' IDENTIFIED BY 'your-password';
GRANT ALL PRIVILEGES ON *.* to 'your_new_username'#'your-hostname' WITH GRANT OPTION;
Exit from the root and log in from the <name> you gave above.
mysql -u <your_new_username> -p
For some reason still just typing MySQL does not work. At all. I suggest to make it a habit to use mysql -u <name> -p.
In the terminal, just enter:
mysql -u root -p
Then it will ask the password from you.
I installed MySQL as root user ($SUDO) and got this same issue
Here is how I fixed it:
sudo cat /etc/mysql/debian.cnf
This will show details as:
# Automatically generated for Debian scripts. DO NOT TOUCH! [client] host = localhost user = debian-sys-maint password = GUx0RblkD3sPhHL5 socket = /var/run/mysqld/mysqld.sock [mysql_upgrade] host = localhost user = debian-sys-maint password = GUx0RblkD3sPhHL5 socket = /var/run/mysqld/mysqld.sock
Above we can see the password. But we are just going to use(GUx0RblkD3sPhHL5) that in the prompt.
`mysql -u debian-sys-maint -p
Enter password: `
Now provide the password (GUx0RblkD3sPhHL5).
Now exit from MySQL and log in again as:
`mysql -u root -p
Enter password: `
Now provide the new password. That's all. We have a new password for further uses.
It worked for me.
For those for whom the current answers didn't work can try this (tested on macOS):
mysql -h localhost -u root -p --protocol=TCP
After this, a password will be asked from you and you should use your OS user password. Then when you get into MySQL you can run:
select Host, User from mysql.user;
And you should see:
MySQL [(none)]> select Host, User from mysql.user;
+-----------+------------------+
| Host | User |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+------------------+
And from here you can change the configurations and edit the password or modify the grants.
Please read the official documentation: MySQL: How to Reset the Root Password
If you have access to a terminal:
MySQL 5.7.6 and later:
mysql
mysql> ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';
MySQL 5.7.5 and earlier:
mysql
mysql> SET PASSWORD FOR 'root'#'localhost' = PASSWORD('MyNewPass');
I am using mysql-5.7.12-osx10.11-x86_64.dmg on Mac OS X.
The installation process automatically sets up a temporary password for the root user. You should save the password. The password can not be recovered.
Follow the instructions:
Go to cd /usr/local/mysql/bin/
Enter the temporary password (which would look something like, "tsO07JF1=>3")
You should get the mysql> prompt.
Run, SET PASSWORD FOR 'root'#'localhost' = PASSWORD('{YOUR_PASSWORD}'); If you wish to set your password: "root" then the command would be, SET PASSWORD FOR 'root'#'localhost' = PASSWORD('root');
Run ALTER USER 'root'#'localhost' PASSWORD EXPIRE NEVER;
Run exit
Run ./mysql -u root -p
Type your password. In my case I would type, "root" (without quote)
That's all.
For convenience, you should add "/usr/local/mysql/bin" to your PATH environment variable.
Now from anywhere you can type ./mysql -u root -p and then type the password and you will get the mysql> prompt.
The answer may sound silly, but after wasting hours of time, this is how I got it to work:
mysql -u root -p
I got the error message
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
Even though I was typing the correct password (the temporary password you get when you first install MySQL).
I got it right when I typed in the password when the password prompt was blinking.
If you have MySQL as part of a Docker image (say on port 6606) and an Ubuntu install (on port 3306) specifying the port is not enough:
mysql -u root -p -P 6606
will throw:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
as it's trying to connect to localhost by default, specifying your local IP address fixes the issue:
mysql -u root -p -P 6606 -h 127.0.0.1
Year 2021.
Answer for Ubuntu 20.04 (Focal Fossa) (maybe other distributions as well).
After days of wandering around... and having none of those answers working for me, I did this and it worked!
Always in a Bash shell:
sudo systemctl disable mysql
In order to stop the daemon from starting on boot.
sudo apt purge mysql-server
and
sudo apt purge mysql-community-server*
There, it warns you you'll erase configuration files... so it's working! Because those are the ones making trouble!
sudo autoremove
To delete all the left behind packages.
Then (maybe it's optional, but I did it) reboot.
Also, I downloaded mysql-server-8.0 from the official MySQL webpage:
sudo apt install mysql-server
A signal that it's working is that when you enter the command above, the system asks you to enter the root password.
Finally:
mysql -u root -p
And the password you entered before.
If the problem still exists, try to force changing the password.
Stop MySQL Server (on Linux):
/etc/init.d/mysql stop
Stop MySQL Server (on Mac OS X):
mysql.server stop
Start the mysqld_safe daemon with --skip-grant-tables:
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;
Stop MySQL Server (on Linux):
/etc/init.d/mysql stop
Stop MySQL Server (on Mac OS X):
mysql.server stop
Start the MySQL server service and test to log in by root:
mysql -u root -p
I also came across the same problem. I did:
Open your cmd
Navigate to C:\Program Files\MySQL\MySQL Server 8.0\bin>
(where MySQL Server 8.0 may be different depending on the server you installed)
Then put the following command mysql -u root -p
It will prompt for the password... simply hit Enter, as sometimes the password you entered while installing is changed by to blank.
Now you can simply access the database.
This solution worked for me on the Windows platform.
By default, the password will be null, so you have to change the password by doing the below steps.
Connect to MySQL
root# mysql
Use mysql
mysql> update user set password=PASSWORD('root') where User='root';
Finally, reload the privileges:
mysql> flush privileges;
mysql> quit
Just one line and it solved my issue.
sudo dpkg-reconfigure mysql-server-5.5
In Ubuntu 16.04 (Xenial Xerus) and MySQL version 5.7.13, I was able to resolve the problem with the steps below:
Follow the instructions from section B.5.3.2.2 Resetting the Root Password: Unix and Unix-Like Systems
MySQL 5.7 reference manual
When I tried #sudo mysqld_safe --init-file=/home/me/mysql-init & it failed. The error was in /var/log/mysql/error.log:
2016-08-10T11:41:20.421946Z 0 [Note] Execution of init_file '/home/me/mysql/mysql-init' started.
2016-08-10T11:41:20.422070Z 0 [ERROR] /usr/sbin/mysqld: File '/home/me/mysql/mysql-init' not found (Errcode: 13 - Permission denied)
2016-08-10T11:41:20.422096Z 0 [ERROR] Aborting
The file permission of mysql-init was not the problem. We need to edit AppArmor permissions.
Edit by sudo vi /etc/apparmor.d/usr.sbin.mysqld
....
/var/log/mysql/ r,
/var/log/mysql/** rw,
# Allow user init file
/home/pranab/mysql/* r,
# Site-specific additions and overrides. See local/README for details.
#include <local/usr.sbin.mysqld>
}
Do sudo /etc/init.d/apparmor reload
Start mysqld_safe again. Try step 2 above. Check file /var/log/mysql/error.log. Make sure there is no error and the mysqld is successfully started.
Run mysql -u root -p
Enter password:
Enter the password that you specified in mysql-init. You should be able to log in as root now.
Shutdown mysqld_safe by sudo mysqladmin -u root -p shutdown
Start mysqld the normal way by sudo systemctl start mysql
While the top answer (with mysqladmin) worked on macOS v10.15 (Catalina), it did not work on Ubuntu. Then I tried many of the other options, including a safe start for MySQL, but none worked.
Here is one that does:
At least for the version I got 5.7.28-0ubuntu0.18.04.4 answers were lacking IDENTIFIED WITH mysql_native_password. 5.7.28 is the default on the current LTS and thus should be the default for most new new systems (till Ubuntu 20.04 (Focal Fossa) LTS comes out).
I found Can't set root password MySQL Server and now applied
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'your_pass_here';
which does work.
The error that I faced was:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
It was a problem with the port running on.
By default, MySQL is running on port 3306.
You can check that on by running
in a 32-bit system:
sudo /opt/lampp/manager-linux.run
in a 64-bit system:
sudo /opt/lampp/manager-linux-x64.run
and click on the Configure button.
In my case the port was running on 3307, and I used the command
mysql -u root -p -P 3307 -h 127.0.0.1
Copied from this link, I had the same problem and this solved the problem. After we add a password for the database, we need to add -p (password-based login), and then enter the password. Otherwise, it will return this error:
mysql -u root -p
Because your error message says "PASSWORD: YES" this means you are are using the wrong password. This happened to me also. Luckily I remembered my correct password, and was able to make the DB connection work.
In recent MySQL versions there isn't any password in the mysql.user table.
So you need to execute ALTER USER. Put this one line command into the file.
ALTER USER 'root'#'localhost' IDENTIFIED BY 'MyNewPass';
And execute it as an init file (as the root or mysql user):
mysqld_safe --init-file=/home/me/mysql-init &
MySQL server need to be stopped to start mysqld_safe.
Also, there may be a problem with AppArmor permissions to load this init file. Read more in AppArmor and MySQL.
If you haven't set password yet, then run mysql -uroot. It works for me.
On Mac, if you have a problem in logging in with the first password you were given in installation, maybe you can just simply kill the MySQL process and then try.
So:
run the following command to find the PID of MySQL:
ps -aef | grep mysql | grep -v grep
kill the process:
kill -15 [process id]
Then you can log in with the initial password using this command:
mysql -uroot -p
Which asks you to enter your password. Just enter the initial password.
I've installed mysql5 using Macports and the installation appears to check out but I cannot login to the server at all.
This is what I did:
sudo port install mysql5-server
This builds and installs fine.
sudo /opt/local/lib/mysql5/bin/mysql_install_db --user=mysql
This runs fine as well. It outputs the following:
Installing MySQL system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'
/opt/local/lib/mysql5/bin/mysqladmin -u root -h LeoMacBook.local password 'new-password'
Alternatively you can run:
/opt/local/lib/mysql5/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /opt/local ; /opt/local/lib/mysql5/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /opt/local/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /opt/local/lib/mysql5/bin/mysqlbug script!
Now...let's follow the instructions exactly. I start the server:
sudo /opt/local/lib/mysql5/bin/mysqld_safe &
Server is running fine.
When I try to change the root password, I CANNOT log in.
LeoMacBook:bin leonardteo$ /opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'
/opt/local/lib/mysql5/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'#'localhost' (using password: NO)'
I'm at wits end.
I've started the server with --skip-grant-tables. With this, I can load up mysql fine from the command line and I'm connected to the server. When I run SELECT * FROM mysql.user;, it returns an empty set! With this, I've tried to create a new user by invoking the command:
CREATE USER 'root'#'localhost' IDENTIFIED BY 'root';
But this doesn't work. I get the error:
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
I cannot get this working. It seems I am so close, yet the root user seems to be missing.
Any ideas?
Leonard
Once you've started up mysql with --skip-grant-tables, issue a flush privileges; query. This'll re-enable the permissions system and allow you to run the usual grant and create user queries.