很多时候, 我们连接不到数据库的原因, 就是因为数据库的用户名和密码配置不正确
可以选择项目中的 config→database.PHP 文件进行配置
如果上述方法无效, 那请检查 MySQL 数据库的版本
MySQL8.0 后的高版本数据库所使用的密码是 caching_sha2_password 加密, 先前版本是 mysql_native_password 加密
因此, 解决的方式有以下几种
1, 通过 Navicate 修改加密方式
我们打开 Navicate, 选择 用户 菜单栏, 选择 root 用户, 双击打开 或者 点击编辑用户
点击插件下拉框, 选择 mysql_native_password
*** 注意: 请重新输入密码!!! 请重新输入密码!!! 请重新输入密码!!!
因为现在文本框中的密码是加密后的, 不是真正的密码!
2, 使用 CMD 命令行修改加密方式
win+R 打开运行窗口, 输入 cmd
在命令行中输入 MySQL -u root -p
弹出 Enter password: 输入密码
在进入 MySQL 编辑后使用命令: ALTER USER [email protected]/* <![CDATA[ */!function(t,e,r,n,c,a,p){try{t=document.currentScript||function(){for(t=document.getElementsByTagName('script'),e=t.length;e--;)if(t[e].getAttribute('data-yjshash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-yjsemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%' ('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/* ]]> */ IDENTIFIED WITH mysql_native_password BY'此处填写 password';
把新版本加密方式 caching_sha2_password 改为旧加密方式 mysql_native_password
上述命令也可以在 Navicate 中使用新建查询执行
来源: http://www.bubuko.com/infodetail-3810741.html