如何使用 MySQL(使用密码:NO)调试 SchemaSpy 的连接问题?

How to debug connection problem for SchemaSpy with MySQL (using password: NO)?

我的机器上有 no-login mysql 运行ning 变体。所以我只输入 mysql 以获得 mysql 客户端 shell.

否,当我试图让 SchemaSpy 连接到 mysql 时失败了:

# try with my user:
java -jar schemaSpy_5.0.0.jar -t mysql -dp /home/bodo/bin/mysql_conn/mysql-connector-java-5.1.49/mysql-connector-java-5.1.49-bin.jar -host localhost -u bodo -db ibo -o /home/bodo/bin/schemaspy/ibo
Using database properties:
  [schemaSpy_5.0.0.jar]/net/sourceforge/schemaspy/dbTypes/mysql.properties
Thu Feb 10 17:01:05 CET 2022 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

Failed to connect to database URL [jdbc:mysql://localhost/ibo]

java.sql.SQLException: Access denied for user 'bodo'@'localhost' (using password: NO)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3933)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3869)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:864)
    at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1707)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1217)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2189)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2220)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2015)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:768)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:403)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:385)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:323)
    at net.sourceforge.schemaspy.SchemaAnalyzer.getConnection(SchemaAnalyzer.java:582)
    at net.sourceforge.schemaspy.SchemaAnalyzer.analyze(SchemaAnalyzer.java:157)
    at net.sourceforge.schemaspy.Main.main(Main.java:42)

# try without user does not work at all
bodo@bodo-work:~/bin/schemaspy$ java -jar schemaSpy_5.0.0.jar -t mysql -dp /home/bodo/bin/mysql_conn/mysql-connector-java-5.1.49/mysql-connector-java-5.1.49-bin.jar -host localhost -db ibo -o /home/bodo/bin/schemaspy/ibo

net.sourceforge.schemaspy.Config$MissingRequiredParameterException: Required parameter '-u' was not specified.

所以重点是Access denied for user 'bodo'@'localhost' (using password: NO)

我该如何调试它或者我需要如何更改我的 MySQL 设置才能让 SchemaSpy 运行?

我已通过授予相关用户访问数据库的权限并使用密码解决了连接问题。

当你遇到这种情况时:

mysql -u bodo
ERROR 1045 (28000): Access denied for user 'bodo'@'localhost' (using password: NO)

并且您没有匿名用户

这可以帮助:

  • ALTER USER 'bodo'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_pssw';
  • GRANT ALL PRIVILEGES ON *.* TO 'bodo'@'localhost' WITH GRANT OPTION;

别忘了FLUSH PRIVILEGES;.

那么你应该可以使用:

mysql -u bodo -p ibo -h localhost
Enter password: 
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 8.0.28-0ubuntu0.20.04.3 (Ubuntu)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

参考资料

AskUbuntu, SO1, SO2, Docs.