【MySQL 8】MySQL8 的遇到的问题

安装MySQL8

安装步骤

http://dev.mysql.com/get/mysql-apt-config_0.8.16-1_all.deb
dpkg -i mysql-apt-config_0.8.16-1_all.deb

创建用户、赋予权限、更改、删除用户信息

MySQL5.7.25

 # 新建、赋予权限
 grant all privileges on *.* to admin@'localhost' identified by 'admins_password' with grant option;
 flush privileges;

# 更改用户 
 ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码'; 

MySQL 8

# 删除、
drop user admin@localhost;
flush privileges;

# 新建、赋予权限(必须分开进行)
create user admin@localhost identified by 'admins_password';
grant all privileges on *.* to admin@'localhost' with grant option;

# 更改用户
ALTER USER 'root'@'localhost' IDENTIFIED  BY '你的密码';

Laravel 连接MySQL8 配置mysql

SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
原因在于:
用户的 Authentication type 默认为 caching_sha2_password,导致数据库连接错误,抛出如下异常:
Illuminate\Database\QueryException : SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
所以解决方法如下:

方法一:通过修改MySQL配置

# /etc/mysql/my.cnf
[mysqld]
default_authentication_plugin = mysql_native_password

systemctl restart mysql

# 重新创建用户(使用  mysql_native_password  模式)
mysql -u root -p
drop user admin@localhost;
flush privileges;
create user admin@localhost identified with mysql_native_password by 'admins_password';
grant all privileges on *.* to admin@'localhost' with grant option;

方法二:修改laravel 配置(此方法未测试)

参考:https://github.com/laravel/framework/pull/23948

docker mysql8 安装

Dockerfile:https://github.com/docker-library/mysql/tree/master/8.0

[ERROR] [MY-010187] [Server] Could not open file ‘/var/log/mysql/error.log’ for error logging: Permission denied

chown 999:999 /var/log/mysql/error.log

mysqld: Error on realpath() on ‘/var/lib/mysql-files’ (Error 2 - No such file or directory)

# Dockerfile
RUN mkdir /var/lib/mysql-files

猜你喜欢

转载自blog.csdn.net/qq_22227087/article/details/109555148