美文网首页
mac安装mysql@8.0.1 踩坑记录

mac安装mysql@8.0.1 踩坑记录

作者: 扶搏森 | 来源:发表于2019-05-08 17:19 被阅读0次

通过homebrew和安装包安装mysql是一顿回车就结束了,在项目中使用时报错

node不支持root登录

{ Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
    at Handshake.Sequence._packetToError (/Users/chenpan/Desktop/ghChat/server/node_modules/mysql/lib/protocol/sequences/Sequence.js:52:14)
    at Handshake.ErrorPacket (/Users/chenpan/Desktop/ghChat/server/node_modules/mysql/lib/protocol/sequences/Handshake.js:130:18)
    at Protocol._parsePacket (/Users/chenpan/Desktop/ghChat/server/node_modules/mysql/lib/protocol/Protocol.js:279:23)
    at Parser.write (/Users/chenpan/Desktop/ghChat/server/node_modules/mysql/lib/protocol/Parser.js:76:12)
    at Protocol.write (/Users/chenpan/Desktop/ghChat/server/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/Users/chenpan/Desktop/ghChat/server/node_modules/mysql/lib/Connection.js:103:28)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at TCP.onread (net.js:594:20)
    --------------------
    at Protocol._enqueue (/Users/chenpan/Desktop/ghChat/server/node_modules/mysql/lib/protocol/Protocol.js:145:48)
    at Protocol.handshake (/Users/chenpan/Desktop/ghChat/server/node_modules/mysql/lib/protocol/Protocol.js:52:23)
    at PoolConnection.connect (/Users/chenpan/Desktop/ghChat/server/node_modules/mysql/lib/Connection.js:130:18)
    at Pool.getConnection (/Users/chenpan/Desktop/ghChat/server/node_modules/mysql/lib/Pool.js:48:16)
    at Promise (/Users/chenpan/Desktop/ghChat/server/utils/db.js:13:8)
    at new Promise (<anonymous>)
    at query (/Users/chenpan/Desktop/ghChat/server/utils/db.js:12:32)
    at Object.findDataByName (/Users/chenpan/Desktop/ghChat/server/models/userInfo.js:44:10)
    at module.exports (/Users/chenpan/Desktop/ghChat/server/controllers/register.js:8:19)
    at dispatch (/Users/chenpan/Desktop/ghChat/server/node_modules/koa-router/node_modules/koa-compose/index.js:44:32)
    at next (/Users/chenpan/Desktop/ghChat/server/node_modules/koa-router/node_modules/koa-compose/index.js:45:18)
    at /Users/chenpan/Desktop/ghChat/server/node_modules/koa-router/lib/router.js:345:16
    at dispatch (/Users/chenpan/Desktop/ghChat/server/node_modules/koa-router/node_modules/koa-compose/index.js:44:32)
    at /Users/chenpan/Desktop/ghChat/server/node_modules/koa-router/node_modules/koa-compose/index.js:36:12
    at dispatch (/Users/chenpan/Desktop/ghChat/server/node_modules/koa-router/lib/router.js:350:31)
    at dispatch (/Users/chenpan/Desktop/ghChat/server/node_modules/koa-compose/index.js:42:32)
    at next (/Users/chenpan/Desktop/ghChat/server/node_modules/koa-compose/index.js:43:18)
    at bodyParser (/Users/chenpan/Desktop/ghChat/server/node_modules/koa-bodyparser/index.js:86:11)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
  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 }

不支持root密码登录

const pool = mysql.createPool({
  user: dbConfig.user,
  password: dbConfig.password,
  database: dbConfig.database,
  host: dbConfig.host,
});

通过设置才能用 root登录

stackoverflow

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YourRootPassword';
-- or
CREATE USER 'foo'@'%' IDENTIFIED WITH mysql_native_password BY 'bar';
-- then
FLUSH PRIVILEGES;

通过homebrew安装需要重新设置root密码

设置密码的复杂度

mysql_secure_installation
set global validate_password.policy=0;
set global validate_password.length=4;

改变/etc/my.cnf中的配置项

Can't connect to local MySQL serverthrough socket '/var/lib/mysql/mysql.sock'(2)
/usr/sbin/mysqld:unknown variable 'default-character-set=utf8'

需要设置编码规则

我的配置

[client]
default-character-set=utf8
port=3306
socket=/tmp/mysql.sock

[mysqld]
port=3306
socket=/tmp/mysql.sock
key_buffer_size=16M
max_allowed_packet=128M
character_set_server=utf8 

[mysqldump]
quick

中间遇到很多问题,重装了好几次

相关文章

网友评论

      本文标题:mac安装mysql@8.0.1 踩坑记录

      本文链接:https://www.haomeiwen.com/subject/cjevoqtx.html