1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Node.js: MySQL 8.0 で接続エラーが出た時の対策

Last updated at Posted at 2022-01-09

次のエラーが出た時の対策です。

  code: 'ER_NOT_SUPPORTED_AUTH_MODE',
  errno: 1251,
  sqlMessage: 'Client does not support authentication protocol requested by server; consider upgrading MySQL client',
  sqlState: '08004',
  fatal: true

エラーが出るプログラム

maria_version.js
#! /usr/local/bin/node
// ---------------------------------------------------------------
//	maria_version.js
//
//					Jan/09/2022
//
// ---------------------------------------------------------------
'use strict'

// ---------------------------------------------------------------
console.error ("*** 開始 ***")

var mysql = require('mysql')
// var mysql = require('mysql2')

var connection = mysql.createConnection ({
	host: 'localhost',
	user: 'scott',
	password: 'tiger123'
	})

connection.query("select version()", function (err, rows)
	{
  	if (err) throw err
  	console.log (rows.length)
  	console.log (rows[0])

	connection.end()
	console.error ("*** 終了 ***")
	})

解決方法

require('mysql')


>を

>```text
require('mysql2')

にすれば、問題は解決します。

実行結果

*** 開始 ***
1
{ 'version()': '8.0.27-0ubuntu0.20.04.1' }
*** 終了 ***

MySQL サーバーで対処することもできます。

mysql> ALTER USER scott@localhost IDENTIFIED WITH mysql_native_password BY 'tige
r123';
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?