mysql - sqoop导入mysql报错-通信链接失败

标签 mysql hadoop hdfs sqoop

我正在尝试连接到 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)

最佳答案

您应该在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;

关于mysql - sqoop导入mysql报错-通信链接失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38807404/

相关文章:

mysql - 连接到数据库 Perl

java - 使用 gcloud dataproc 创建配置单元表不适用于 unicode 分隔符

java - Hadoop 的命令 start-dfs.sh 显示一个奇怪的错误

php - Mysqli_stmt_get_result 在 PHP 5.5.3 中返回 fatal error

php - TextArea 数据在存储到 MySQL 之前进行清理

hadoop - ssh 登录后立即关闭连接

ubuntu - 如何在Windows中访问Ubuntu VM HDFS?

hadoop - 无法在 WebHdfs 中创建目录或文件

java.lang.ClassNotFoundException : com. mysql.jdbc.Driver。

java - Map Reduce 程序抛出异常 IOException "Type mismatch in key from map"