zoukankan      html  css  js  c++  java
  • node连接Mysql报错ER_NOT_SUPPORTED_AUTH_MODE

    报错信息

    本人系统安装的是mysql-installer-community-8.0.18.0.msi这个版本,然后我本地使用node-mysql去连接数据库。

    test.js文件

    var mysql  = require('mysql');  
     
    var connection = mysql.createConnection({     
      host     : 'localhost',     //本机地址
      user     : 'root',          //用户
      password : '123456',        //密码
      port: '3306',               //端口号
      database: 'test'            //要连接的数据库
    }); 
     
    connection.connect();
     
    var  sql = 'SELECT * FROM table1';   //查询table1表的所有数据
    
    connection.query(sql,function (err, result) {
            if(err){
              console.log('[SELECT ERROR] - ',err.message);
              return;
            }
     
           console.log('--------------------------SELECT----------------------------');
           console.log(result);
           console.log('------------------------------------------------------------
    
    ');  
    });
     
    connection.end();

    运行node test.js

    F:All Project	est
    ode>node test.js
    [SELECT ERROR] -  ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client

    报错[SELECT ERROR] - ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client

    报错原因

    mysql8.0以上加密方式,Node还不支持。

    解决方案

    第一步谷歌
    查到了 https://stackoverflow.com/questions/50093144/mysql-8-0-client-does-not-support-authentication-protocol-requested-by-server
    这个答案,和我报错的步骤基本一样,按照这个进行操作,登录mysql使用这个

    mysql> alter user 'root'@'localhost' identified with mysql_native_password by '123456';
    Query OK, 0 rows affected (0.27 sec)
    
    mysql> flush privileges;
    Query OK, 0 rows affected (0.08 sec)

    再次运行

    F:All Project	est
    ode>node test.js
    --------------------------SELECT----------------------------
    [ RowDataPacket {
        id: '1',
        name: 'Google',
        url: 'https://www.google.com',
        alexa: '1',
        country: 'USA' },
      RowDataPacket {
        id: '3',
        name: 'Facebook',
        url: 'https://www.facebook.com',
        alexa: '3',
        country: 'USA' },
      RowDataPacket {
        id: '4',
        name: '微博',
        url: 'https://www.weibo.com',
        alexa: '4',
        country: 'CN' } ]
    ------------------------------------------------------------

    成功获得数据。

  • 相关阅读:
    C++-蓝桥杯-小数第n位[除法模拟]
    C++-蓝桥杯-合成植物[并查集][模板题]
    Overleaf操作
    三维向量差积,以及应用
    C++-蓝桥杯-分考场[2017真题][搜索][无向图染色]
    C++-POJ1094-Sorting It All Out[拓扑排序][邻接矩阵]
    C++-LUOGU1059-明明的随机数[堆排序]
    C++-快速排序[STL][快速排序][并归排序][堆排序]
    C++-蓝桥杯-波动数组[2014真题][DP优化]
    C++-蓝桥杯-[T1~T3][结果填空题][2015真题][水题]
  • 原文地址:https://www.cnblogs.com/jing-tian/p/11688073.html
Copyright © 2011-2022 走看看