【问题标题】:Sqoop import mysql error - communications link failuresqoop导入mysql报错——通讯链接失败
【发布时间】:2016-12-12 22:36:08
【问题描述】:

我正在尝试连接mysql并通过sqoop导入mysql。

但是,出现通信链路故障错误。

这是我的配置文件。

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

b) mysql 运行良好。

[root@localhost edureka]# sqoop import --connect jdbc:mysql://192.168.56.1/Edureka --table Employee --username root -P --target-dir /sqoopOut1 -m 1;

Warning: /usr/lib/hcatalog does not exist! HCatalog jobs will fail.
Please set $HCAT_HOME to the root of your HCatalog installation.
Enter password: 
16/08/06 23:34:48 INFO manager.MySQLManager: Preparing to use a MySQL streaming resultset.
16/08/06 23:34:48 INFO tool.CodeGenTool: Beginning code generation
16/08/06 23:34:48 ERROR manager.SqlManager: Error executing statement: 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.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

这是我的日志文件:

    60806 12:33:42 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
160806 12:33:43  InnoDB: Initializing buffer pool, size = 8.0M
160806 12:33:43  InnoDB: Completed initialization of buffer pool
InnoDB: The first specified data file ./ibdata1 did not exist:
InnoDB: a new database to be created!
160806 12:33:43  InnoDB: Setting file ./ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
160806 12:33:44  InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 5 MB
InnoDB: Database physically writes the file full: wait...
160806 12:33:44  InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 5 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
160806 12:33:45  InnoDB: Started; log sequence number 0 0
160806 12:33:45 [Note] Event Scheduler: Loaded 0 events
160806 12:33:45 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.1.73'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Source distribution
160806 23:05:06 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
160806 23:05:06  InnoDB: Initializing buffer pool, size = 8.0M
160806 23:05:06  InnoDB: Completed initialization of buffer pool
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
160806 23:05:06  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
160806 23:05:07  InnoDB: Started; log sequence number 0 44233
160806 23:05:07 [Note] Event Scheduler: Loaded 0 events
160806 23:05:07 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.1.73'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  Source distribution

更新:我已经创建了 Edureka 数据库并创建了 Employee 表。

[root@localhost edureka]# mysql -u root -p

输入密码: 欢迎使用 MySQL 监视器。命令以 ; 结尾或\g。 您的 MySQL 连接 ID 为 3 服务器版本:5.1.73 源码分发

版权所有 (c) 2000、2013,Oracle 和/或其附属公司。保留所有权利。

Oracle 是 Oracle Corporation 和/或其 附属公司。其他名称可能是其各自的商标 所有者。

键入“帮助;”或 '\h' 寻求帮助。输入 '\c' 清除当前输入语句。

mysql> 使用 edureka 读取表信息以补全表名和列名 您可以使用 -A 关闭此功能以加快启动速度

数据库已更改

mysql> select * from employee;
+--------+-------+
| ename  | ecode |
+--------+-------+
| neha   | 101   |
| yogesh | 102   |
+--------+-------+
2 rows in set (0.00 sec)

这就是我的 sql 中“显示授权”的样子:

    mysql> show grants;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost                                                                                                              |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

【问题讨论】:

    标签: mysql hadoop hdfs sqoop


    【解决方案1】:

    你应该在JDBC连接字符串中使用端口号:

    sqoop import --connect jdbc:mysql://192.168.56.1:3306/Edureka --table Employee --username root -P --target-dir /sqoopOut1 -m 1;
    

    此外,您还应该使用主机名代替 IP。
    因此,如果命令 hostname -f 的输出是 computer.name,请在 JDBC 连接字符串中使用它:

    sqoop import --connect jdbc:mysql://computer.name:3306/Edureka --table Employee --username root -P --target-dir /sqoopOut1 -m 1;
    

    【讨论】:

    • 在上述 sqoop 导入中使用 localhost:3306。我收到 Edureka 数据库不存在的错误。但是,我已经创建了数据库
    • 你能从 MySQL 端验证数据库存在吗?
    • 是的,我已经在上面的 UPDATE 中添加了。 mysql数据库存在。
    • 你可以尝试使用hostname -f 命令的输出而不是localhost吗?
    • sqoop 命令有 Edureka(大写 E),您的数据库名称是 edureka(小写 e)- [UNIX 中的 mysql 数据库名称区分大小写] (stackoverflow.com/questions/6134006/…)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-11
    • 2013-05-17
    • 2020-08-10
    • 1970-01-01
    • 1970-01-01
    • 2020-02-17
    • 1970-01-01
    相关资源
    最近更新 更多