It's short tutorial for you if your database was created in Mysql 8, and now it upgraded to Mysql 9 where native password plugin was removed.
I was using Mysql 8. But today I noticed that my Docker has grown too much, so I decided to clean up the outdated files. But I accidentally deleted the built images.
After that, I've re-build my Laradock stack and noticed that the Mysql container started to give an error, as it turned out it was an error about the unknown variable mysql_native_password
.
I tried different approaches that I used to fix it before and nothing helped. Later, I searched a ton of material, but nothing really worked.
Then I noticed that I had a MYSQL_VERSION
variable in the .env
file of laradock with the value latest
and it installed Mysql 9 for me.
I thought that a simple downgrade would help, but after that I was faced with the following version conflict. Somehow, the file ~/.laradock/data/mysql/mysql.ibd
(from variable DATA_PATH_HOST
) changed to Mysql 9 and thus prevented the existing databases from being pulled up.
I still don't understand why. But if anyone has a similar problem. Here's how I solved it.
- Laradock: Remove Run condition
RUN if [ "${MYSQL_VERSION}" \> "8.4.0-0.000" ]; then \
echo 'mysql_native_password=on' >> /etc/mysql/conf.d/my.cnf; \
else \
echo 'default-authentication-plugin=mysql_native_password' >> /etc/mysql/conf.d/my.cnf; \
fi
- Remove
default-authentication-plugin=mysql_native_password
andmysql_native_password=on
frommy.cnf
file
[mysqld]
skip-grant-tables
- If you use laradock, so rebuild and run mysql container with
skip-grant-tables
. Run:docker-compose up -d --build mysql
- Enter mysql container:
docker-compose exec mysql bash
- Enter mysql by typing
mysql
in console FLUSH PRIVILEGES;
- Create new root user with caching_sha2_password plugin
CREATE USER 'admin'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'admin';
- Grant all privileges to MySQL User on all databases
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost';
- Select all users with native password:
SELECT user, host, plugin FROM mysql.user WHERE plugin LIKE '%native%';
FLUSH PRIVILEGES;
- And regenerate password for root and other users with native password
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'root';