连接Mysql8报错:Client does not support authentication protocol requested by server; consider upgradin...

代码:

package edu.nwpu.ad.service;

import com.github.shyiko.mysql.binlog.BinaryLogClient;
import com.github.shyiko.mysql.binlog.event.DeleteRowsEventData;
import com.github.shyiko.mysql.binlog.event.EventData;
import com.github.shyiko.mysql.binlog.event.UpdateRowsEventData;
import com.github.shyiko.mysql.binlog.event.WriteRowsEventData;

import java.io.IOException;

/**
 * 解析Binlog
 */
public class BinlogServiceTest {
    public static void main(String[] args) throws IOException {
        BinaryLogClient client = new BinaryLogClient(
                "127.0.0.1",
                3306,
                "root",
                "123654"
        );
        /**
         * 可以配置client直接去读取哪一个binlog
         * 如果不配置,默认读取最新的
         */
        // client.setBinlogFilename();
        /**
         * 设置从哪一个位置开始监听
         * 默认从最新的位置监听
         */
        // client.setBinlogPosition();

        client.registerEventListener(event -> {
            EventData data = event.getData();
            if (data instanceof UpdateRowsEventData) {
                System.out.println("----------Update----------");
                System.out.println(data.toString());
            } else if (data instanceof WriteRowsEventData) {
                System.out.println("----------Write----------");
                System.out.println(data.toString());
            } else if (data instanceof DeleteRowsEventData) {
                System.out.println("----------Delete----------");
                System.out.println(data.toString());
            }
        });

        client.connect();
    }
}

运行报错:Client does not support authentication protocol requested by server; consider upgrading MySQL client...

解决办法:

mysql> USE mysql;
Database changed

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123654';
Query OK, 0 rows affected (0.02 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

然后重启MySQL服务。
问题解决~!

你可能感兴趣的:(连接Mysql8报错:Client does not support authentication protocol requested by server; consider upgradin...)