mysql踩坑

关于安装

1报错:ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client具体代码如下:

复制代码
import mysql from "mysql"

//连接数据库
const db=mysql.createPool({
  host:'127.0.0.1',
  user:"root",  //一定要搞清楚这里的user之前设置的是哪个
  port:3306,
  password:"admin123",
  database:'test'
})

//测试数据库是否连接成功
db.query('select1',(err,result)=>{
  if(err){
    console.log("err",err.message)
    return
  }
  console.log("result:",result)
})

解决办法:

1进入mysql安装目录下的bin目录执行cmd,比如我的安装路径是C:\Windows\System32\cmd.exe

1.启动数据库 net start mysql

2.登录数据库 mysql -u root -p

此时要输入密码;

3.用数据库

eg:有 sys,name , age三个数据库你用哪个就需要执行命令,如下

mysql> use name

  1. alter user 'root'@'localhost' identified with mysql_native_password by '123456';

//123456为数据库密码(这个要记住)

5.flush privileges;

2 测试连接是否成功时,报错

ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select1' at line 1

解决办法:

复制代码
db.query('select 1',(err,result)=>{
  if(err){
    console.log("err",err.message)
    return
  }
  console.log("result:",result)
})
//注意select 1
相关推荐
七度黑光7 小时前
用 openclaw 给故障复盘打分:质量审核自动化实践
运维·服务器·前端·数据库·自动化
qq_283720057 小时前
MySQL技巧(九): Binlog 完整格式解析(ROW 模式,默认)
mysql·binlog·数据恢复
华科易迅8 小时前
Spring 事务(注解)
java·数据库·spring
Java面试题总结8 小时前
MySQL篇 索引失效
数据库·mysql
last demo8 小时前
mysql
运维·数据库·mysql·oracle
kevin_cat10 小时前
oracle 扩展表空间
数据库·oracle
花间相见10 小时前
【MySQL面试题】—— MySQL面试高频问题汇总:从原理到实战,覆盖90%考点
数据库·mysql·面试
高梦轩11 小时前
MySQL 数据库备份与恢复
数据库·oracle
一直都在57211 小时前
Redis(二)
数据库·redis·缓存
TDengine (老段)11 小时前
TDengine IDMP 工业数据建模 —— 属性
大数据·数据库·人工智能·时序数据库·tdengine·涛思数据