704

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?

CC BY-SA 4.0
12

38 Answers 38

507

You can change the encryption of the password like this.

ALTER USER 'yourusername'@'localhost' IDENTIFIED WITH mysql_native_password BY 'youpassword';
CC BY-SA 4.0
11
373

Note: For macOS.

  1. Open MySQL from System Preferences > Initialize Database >
  2. Type your new password.
  3. Choose 'Use legacy password'
  4. Start the Server again.
  5. Now connect the MySQL Workbench

Image description

CC BY-SA 4.0
10
173

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.

CC BY-SA 4.0
7
135

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.

CC BY-SA 4.0
7
93

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.

CC BY-SA 4.0
3
89

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 Sequel Pro to access your database(s) running on that docker container, you are out of luck.

See the Sequel Pro issue 2699

My setup is Sequel Pro 1.1.2 using Docker desktop 2.0.3.0 (macOS 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 Sequel Pro is a NO GO with MySQL 8+

Finally, I abandoned Sequel Pro (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;
CC BY-SA 4.0
6
76

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).

CC BY-SA 3.0
5
67

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:

  1. Enter on mysql console: $ mysql -u root -p, if you don't have a password for root user, then:

  2. Use mysql db: mysql> use mysql;

  3. Alter your user for solve the problem: mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

  4. Exit... mysql> quit;

  5. Done!

CC BY-SA 4.0
4
61

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.

MySQL Web Installer - Home Screen

Clicking on the "Reconfigure" option it will allow to reconfigure the server. Click on "Next" until you reach "Authentication Method".

MySQL Installer - 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.

CC BY-SA 4.0
2
43

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.

CC BY-SA 3.0
1
40

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.

CC BY-SA 4.0
5
24

For Windows 10,

  1. Modify my.ini file in C:\ProgramData\MySQL\MySQL Server 8.0\

    [mysqld]
    default_authentication_plugin=mysql_native_password
    
  2. Restart the MySQL Service.

  3. 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';
      
  4. Open MySQL workbench, and open a new connection using the new user credentials.

I was facing the same issue and this worked.

CC BY-SA 4.0
1
22
  • 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)

Image

Courtesy: UDEMY FAQs answered by Career365 Team

CC BY-SA 4.0
2
  • This worked. Why? I got this error when trying to connect with root and no password, which worked in the command line, but not in Sequel Pro.
    – Volte
    Commented Dec 31, 2018 at 23:50
  • work like charm, full corelation with Thread Start question and please note : your must have Mac os Catalina, docker 19.03, mysql latest images, exection this command $docker run -p 3306:3306 -d --name mysql -e MYSQL_ROOT_PASSWORD=password mysql/mysql-server from dzone website.
    – banzai
    Commented May 24, 2020 at 11:55
22

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 '';
CC BY-SA 4.0
0
18

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 |
+---+
CC BY-SA 4.0
0
13

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
CC BY-SA 4.0
2
10

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

CC BY-SA 4.0
1
  • This worked for me on Centos 7. For some reason, my passwords were saved as caching_sha2_password by default and I was getting error #1251 when trying to log in with phpMyAdmin. Commented Jun 21, 2019 at 14:39
9

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'

CC BY-SA 4.0
0
8

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!)
CC BY-SA 3.0
6

Open my sql command promt:

step 1

then enter mysql password

step 2

finally use:

ALTER USER 'username'@'ip_address' IDENTIFIED WITH mysql_native_password BY 'password';

refer:https://stackoverflow.com/a/49228443/6097074

Thanks.

CC BY-SA 4.0
6

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.

CC BY-SA 4.0
0
6

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

CC BY-SA 4.0
0
5

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';
CC BY-SA 4.0
0
5

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:

  1. sudo apt-get update
  2. sudo apt-get install lsb-release -y
  3. Download a Debian package which update apt sources for you from the MySQL web site.
  4. 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.
  5. sudo apt-get update
  6. sudo apt-get install mysql-client -y
  7. Done. You can now run the new MySQL client and connect with the new authentication method.
CC BY-SA 4.0
1
4

MySQLWorkbench 8.0.11 for macOS addresses this. I can establish connection with root password protected mysql instance running in docker.

CC BY-SA 4.0
1
  • This is what fixed it for me. I was running an older MySQL Workbench 6.3 with a 8.0 server. While many answers here say to downgrade server compatibility, I simply upgraded my Workbench version to the latest 8.0 release (currently 8.0.15).
    – Sum None
    Commented Mar 16, 2019 at 22:19
3

The below solution worked for me enter image description here

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

enter image description here

CC BY-SA 4.0
3

Actually MySql allows two type of authentication at the time of installation.

  1. Password Encryption
  2. Legacy Encryption

enter image description here

Read Here

So by checking legacy authentication the issue was resolved.

CC BY-SA 4.0
1
2

To access mysql using mysql_native_password from other BE container one should use "root"@"%" instead of root@localhost and build again your backend container it should work.

ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'mypasswrd'
CC BY-SA 4.0
1

Try using legacy password while downloading and installing MySql, that helped me. Or follow the method posted by Santhosh Shivan for Mac OS.

CC BY-SA 4.0
1

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.

CC BY-SA 4.0

Not the answer you're looking for? Browse other questions tagged or ask your own question.