【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 
})
相关推荐
Ze3G90nYt10 小时前
Redis 分布式锁进阶第一百三十一篇
数据库·redis·分布式
倔强的石头10610 小时前
《Kingbase护城河》——数据库卡顿急救手册:会话状态深度解析与“僵尸进程”排查实战
数据库
清晨00110 小时前
工业互联网实时数据统计一致性保障 — 基于 Redis Lua 的并发安全方案
redis·安全·lua
焦虑的说说10 小时前
mysql为什么回表会慢
mysql·面试
峥无10 小时前
MySQL 数据库 & 数据表基础操作总结
数据库·mysql
程序边界10 小时前
KES Plus深度体验:当数据库开始“越界“做开发平台
数据库
Amnesia0_010 小时前
MYSQL索引
数据库·mysql
一只fish10 小时前
DB-Engines Ranking 2026年6月数据库排行
数据库
Tipriest_10 小时前
没有nvidia的卡上装sogou拼音的特殊处理
运维·服务器·mysql
啾啾Fun10 小时前
【向量数据库】Milvus:为大规模、高性能而生的企业级向量数据库
数据库·milvus