Typecho——数据库无法连接问题

2024-08-16 10:34:38 浏览数 (4)

报错

对不起,无法连接数据库,请先检查数据库配置再继续进行安装

解决方案

这里主要分为两个版本8.0以下和8.0以上,因为8.0版本后默认的密码认证方式变了;

代码语言:javascript复制
mysql>  select host,user,plugin,authentication_string from mysql.user;
 ----------- ------------------ ----------------------- ------------------------------------------------------------------------ 
| host      | user             | plugin                | authentication_string                                                  |
 ----------- ------------------ ----------------------- ------------------------------------------------------------------------ 
| %         | oyo              | caching_sha2_password | $A$005$6Uc5Cj?])7'^~><wv2CnNz7y/eQsnjIEhN4eA2hHb/2HK4lNqTljQuBmh0 |
| %         | root             | mysql_native_password | *FD04C051D87F8DC4048B64622FEC0C73617EDC51                              |
| localhost | mysql.infoschema | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.session    | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | mysql.sys        | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |
| localhost | oyo              | caching_sha2_password | $A$005$&F6]?f
KhaCTT7IiA1dojLsbyuwl5ILWi/Rkm2f2tPK.G4816Oth8.92Q4D  |
| localhost | root             | mysql_native_password | *FD04C051D87F8DC4048B64622FEC0C73617EDC51                              |
 ----------- ------------------ ----------------------- ------------------------------------------------------------------------ 

MySQL5.7

代码语言:javascript复制
#创建数据库
CREATE DATABASE `database` CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_unicode_ci';
#可根据自身情况开启本地权限或者远程权限
#开启本地权限
GRANT ALL PRIVILEGES ON *.* TO 'userName'@'localhost' IDENTIFIED BY 'passworld' WITH GRANT OPTION;
#开启远程权限
GRANT ALL PRIVILEGES ON *.* TO 'userName'@'%' IDENTIFIED BY 'passworld' WITH GRANT OPTION;
#刷新权限
flush privileges;

MySQL8.0

针对已创建用户

代码语言:javascript复制
ALTER USER 'user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
ALTER USER 'user'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
flush privileges;

针对新创建用户

!> 这里是为了方便演示,直接赋予了用户所有库表的权限,实际操作中建议赋予指定库表的权限;

代码语言:javascript复制
#创建数据库
CREATE DATABASE `database` CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_unicode_ci';
#创建用户
CREATE USER username@'%' IDENTIFIED WITH mysql_native_password BY 'password';
CREATE USER username@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
#授权
grant all on *.* to 'username'@'%';
grant all on *.* to 'username'@'localhost';
#刷新权限
flush privileges;

1 人点赞