Friday, September 27, 2019

hadoop - Sqoop import mysql error - communications link failure



I am trying to connect to mysql and import mysql through sqoop.




however, getting communications link failure error.



Here is my configuration file.



[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 is running fine.



[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


Here is my log file :




    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


Update : I have created Edureka database and created Employee table.




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


Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.73 Source distribution



Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.




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> use edureka
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A




Database changed



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



This is how 'show grants' look like on my 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)

Answer



you should use port number in JDBC connection string:



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


further more, you also should use hostname instead for IP.
so if output of command hostname -f is computer.name use this in JDBC connection string:




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

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...