【Mysql 连接报错】

文章目录

遇到问题

socket: auth failed .../.../lualib/skynet/socketchannel.lua:482: errno:1251, msg:Client does not support authentication protocol requested by server; consider upgrading MySQL client,sqlstate:08004

查看用户信息

  1. use mysql;
  2. select user,host,plugin from user where user='root';

出现:

这里建议新建用户然后查看(root 不知道为什么修改不了)

  1. create user 'cauchy'@'%' identified by 'root';

创建用户 cauchy,允许任何 IP 访问 %,密码 root

  1. grant all privileges on chat.* to 'cauchy'@'%';

授权所有权限给任何 IP 登上的用户 cauchy 访问 databasechat 数据库的所有表 chat.*

执行:select user,host,plugin from user where user='cauchy';

mysql 8 之前的版本中加密规则是 mysql_native_password ,而在 mysql 8 之后,加密规则是 caching_sha2_password

修改加密规则

alter user 'cauchy'@'%' identified with mysql_native_password by 'root';

成功连入mysql

lua 复制代码
local ok, db = pcall(mysql.connect, {
    host = "127.0.0.1",
    port = 3306,
    database = "chat",
    user = "cauchy",
    password = "root",
    max_packet_size = 1024 * 1024, 
    charset = "utf8",
    on_connect = function() end 
})
相关推荐
你的保护色5 小时前
数据库第一章-基础知识学习
数据库·学习
倔强的石头_5 小时前
《Kingbase护城河》——数据库卡顿急救手册:会话状态深度解析与“僵尸进程”排查实战
数据库
x***r1515 小时前
Postman-win64-7.3.5-Setup安装配置教程(Windows 详细版)
开发语言·lua
ManageEngine卓豪5 小时前
数据库可观测性:MySQL与Redis监控核心监控指标与全栈运维解决方案
数据库·redis·mysql·数据库性能·数据库监控
真实的菜5 小时前
Redis 从入门到精通(十四):Redis 7.x 新特性全解 —— 系列收官之作
数据库·redis·缓存
哭哭啼5 小时前
pgSql 事务篇
java·数据库·postgresql
霸道流氓气质6 小时前
从MySQL到云原生:全面解析阿里云PolarDB数据库及其与MySQL的核心差异
数据库·mysql·云原生
这个DBA有点耶6 小时前
时序数据库选型:吞吐、压缩与查询延迟的均衡之术
数据库·sql·架构·时序数据库·dba
snow@li6 小时前
数据库:MySQL vs PostgreSQL 详尽对比(2026版)
java·mysql·postgresql