sqoop连接MySQL失败

使用命令报错:

#测试能否成功连接数据库
sqoop list-databases --connect jdbc:mysql://master:3306/?useSSL=false --username sqoop --password 123456

报错信息如下:

ERROR manager.CatalogQueryManager: Failed to list databases

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

完整信息在下面:

  • Warning: /usr/local/sqoop/../hcatalog does not exist! HCatalog jobs will fail.
    Please set $HCAT_HOME to the root of your HCatalog installation.
    Warning: /usr/local/sqoop/../accumulo does not exist! Accumulo imports will fail.
    Please set $ACCUMULO_HOME to the root of your Accumulo installation.
    23/03/08 12:44:29 INFO sqoop.Sqoop: Running Sqoop version: 1.4.7
    23/03/08 12:44:29 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead.
    23/03/08 12:44:30 INFO manager.MySQLManager: Preparing to use a MySQL streaming resultset.
    23/03/08 12:44:30 ERROR manager.CatalogQueryManager: Failed to list databases
    com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
    
    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    	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:425)
    	at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:990)
    	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:342)
    	at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2188)
    	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2221)
    	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2016)
    	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:776)
    	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:425)
    	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:386)
    	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
    	at java.sql.DriverManager.getConnection(DriverManager.java:664)
    	at java.sql.DriverManager.getConnection(DriverManager.java:247)
    	at org.apache.sqoop.manager.SqlManager.makeConnection(SqlManager.java:904)
    	at org.apache.sqoop.manager.GenericJdbcManager.getConnection(GenericJdbcManager.java:59)
    	at org.apache.sqoop.manager.CatalogQueryManager.listDatabases(CatalogQueryManager.java:57)
    	at org.apache.sqoop.tool.ListDatabasesTool.run(ListDatabasesTool.java:49)
    	at org.apache.sqoop.Sqoop.run(Sqoop.java:147)
    	at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)
    	at org.apache.sqoop.Sqoop.runSqoop(Sqoop.java:183)
    	at org.apache.sqoop.Sqoop.runTool(Sqoop.java:234)
    	at org.apache.sqoop.Sqoop.runTool(Sqoop.java:243)
    	at org.apache.sqoop.Sqoop.main(Sqoop.java:252)
    Caused by: java.net.ConnectException: Connection refused (Connection refused)
    	at java.net.PlainSocketImpl.socketConnect(Native Method)
    	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    	at java.net.Socket.connect(Socket.java:589)
    	at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:211)
    	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:301)
    	... 24 more
    23/03/08 12:44:30 ERROR sqoop.Sqoop: Got exception running Sqoop: java.lang.RuntimeException: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
    
    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    java.lang.RuntimeException: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
    
    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    	at org.apache.sqoop.manager.CatalogQueryManager.listDatabases(CatalogQueryManager.java:73)
    	at org.apache.sqoop.tool.ListDatabasesTool.run(ListDatabasesTool.java:49)
    	at org.apache.sqoop.Sqoop.run(Sqoop.java:147)
    	at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)
    	at org.apache.sqoop.Sqoop.runSqoop(Sqoop.java:183)
    	at org.apache.sqoop.Sqoop.runTool(Sqoop.java:234)
    	at org.apache.sqoop.Sqoop.runTool(Sqoop.java:243)
    	at org.apache.sqoop.Sqoop.main(Sqoop.java:252)
    Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
    
    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    	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:425)
    	at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:990)
    	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:342)
    	at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2188)
    	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2221)
    	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2016)
    	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:776)
    	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:425)
    	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:386)
    	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
    	at java.sql.DriverManager.getConnection(DriverManager.java:664)
    	at java.sql.DriverManager.getConnection(DriverManager.java:247)
    	at org.apache.sqoop.manager.SqlManager.makeConnection(SqlManager.java:904)
    	at org.apache.sqoop.manager.GenericJdbcManager.getConnection(GenericJdbcManager.java:59)
    	at org.apache.sqoop.manager.CatalogQueryManager.listDatabases(CatalogQueryManager.java:57)
    	... 7 more
    Caused by: java.net.ConnectException: Connection refused (Connection refused)
    	at java.net.PlainSocketImpl.socketConnect(Native Method)
    	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    	at java.net.Socket.connect(Socket.java:589)
    	at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:211)
    	at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:301)
    	... 24 more
    	
    

原因:

没有开启远程登录,需要修改配置

解决方案:

#查看状态(是inactive状态才对)
sudo ufw status
#查看端口
netstat -an | grep 3306
#如果是127.0.0.1:3306,说明只能本机访问
#0.0.0.0:3306,说明任意注意访问

#编辑端口
#注释掉43行的bind-address
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf 

##修改端口,需要重启虚拟机
sudo reboot

sqoop连接MySQL失败_第1张图片

sqoop连接MySQL失败_第2张图片

成功状态

sqoop连接MySQL失败_第3张图片

你可能感兴趣的:(大数据开发,mysql,sqoop,数据库)