无法从 java 连接到 MySQL 数据库,但可以从普通 MySQL 命令行连接
Can't connect to MySQL database from java but able to connect from plain MySQL command line
我正在尝试使用 mwdumper jar 将维基词典转储导入我使用 MAMP Pro 创建的数据库。这是我正在努力的命令:
java -jar mwdumper-1.25.jar --format=sql:1.5 /Users/med/Downloads/enwiktionary-20171001-pages-articles-multistream.xml --output=mysql://localhost:8889/wiktionay?user=wikiuser&password=wiki2017
运行 带有此命令的 jar 提供以下内容:
> [1] 1209
$ Exception in thread "main" java.io.IOException: Access denied for user 'wikiuser'@'localhost' (using password: NO)
at org.mediawiki.dumper.Dumper.connectMySql(Dumper.java:225)
at org.mediawiki.dumper.Dumper.openOutputFile(Dumper.java:211)
at org.mediawiki.dumper.Dumper.main(Dumper.java:96)
Caused by: java.sql.SQLException: Access denied for user 'wikiuser'@'localhost' (using password: NO)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4074)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4006)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1694)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1244)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2397)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2430)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2215)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:813)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:334)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at org.mediawiki.dumper.Dumper.connectMySql(Dumper.java:221)
... 2 more
当我简单地尝试从终端连接到数据库时,我没有访问问题:
$ /Applications/MAMP/Library/bin/mysql -u wikiuser -p
如相关问题所述,我从 MAMP 界面检查了 "Allow network access to MySQL",但仍然没有帮助。使用 root 也有同样的问题。
知道哪里出了问题吗?
问题是由于 & 运算符 密码 在 URL 中作为单独的命令在发送 URL 在终端上。因此,mysql 永远不会得到 密码。
使用\转义&即
--output=mysql://localhost:8889/wiktionay?user=wikiuser\&password=wiki2017
编辑:04:14 上午,IST
Exception in thread "main" java.lang.IllegalArgumentException:
Expected file stream, got SQL connection?
尝试在末尾传递流文件名,即在 --output 之后是 --format 然后是 /Users/med/Downloads/enwiktionary-20171001-pages-articles-multistream.xml
我正在尝试使用 mwdumper jar 将维基词典转储导入我使用 MAMP Pro 创建的数据库。这是我正在努力的命令:
java -jar mwdumper-1.25.jar --format=sql:1.5 /Users/med/Downloads/enwiktionary-20171001-pages-articles-multistream.xml --output=mysql://localhost:8889/wiktionay?user=wikiuser&password=wiki2017
运行 带有此命令的 jar 提供以下内容:
> [1] 1209
$ Exception in thread "main" java.io.IOException: Access denied for user 'wikiuser'@'localhost' (using password: NO)
at org.mediawiki.dumper.Dumper.connectMySql(Dumper.java:225)
at org.mediawiki.dumper.Dumper.openOutputFile(Dumper.java:211)
at org.mediawiki.dumper.Dumper.main(Dumper.java:96)
Caused by: java.sql.SQLException: Access denied for user 'wikiuser'@'localhost' (using password: NO)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4074)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4006)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1694)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1244)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2397)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2430)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2215)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:813)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:334)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at org.mediawiki.dumper.Dumper.connectMySql(Dumper.java:221)
... 2 more
当我简单地尝试从终端连接到数据库时,我没有访问问题:
$ /Applications/MAMP/Library/bin/mysql -u wikiuser -p
如相关问题所述,我从 MAMP 界面检查了 "Allow network access to MySQL",但仍然没有帮助。使用 root 也有同样的问题。
知道哪里出了问题吗?
问题是由于 & 运算符 密码 在 URL 中作为单独的命令在发送 URL 在终端上。因此,mysql 永远不会得到 密码。
使用\转义&即
--output=mysql://localhost:8889/wiktionay?user=wikiuser\&password=wiki2017
编辑:04:14 上午,IST
Exception in thread "main" java.lang.IllegalArgumentException: Expected file stream, got SQL connection?
尝试在末尾传递流文件名,即在 --output 之后是 --format 然后是 /Users/med/Downloads/enwiktionary-20171001-pages-articles-multistream.xml