Support Questions

Find answers, ask questions, and share your expertise
Announcements
Welcome to the upgraded Community! Read this blog to see What’s New!

Mysql JDBC connection error for ambari installation

avatar
Explorer

sudo apt-get install libmysql-java
Reading package lists... Done
Building dependency tree
Reading state information... Done
libmysql-java is already the newest version (5.1.45-1).
0 upgraded, 0 newly installed, 0 to remove and 92 not upgraded.

 

 

/usr/jdk64/jdk1.8.0_112/bin/java -cp /usr/lib/ambari-agent/DBConnectionVerification.jar:/usr/share/java/mysql-connector-java.jar org.apache.ambari.server.DBConnectionVerification "jdbc:mysql://XXXXXX:3306/ambari" "ambari" "password" com.mysql.jdbc.Driver
ERROR: Unable to connect to the DB. Please check DB connection properties.
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

 

1 ACCEPTED SOLUTION

avatar
Expert Contributor

Hi @Manoj690 

 

Can you copy - "/var/lib/ambari-server/resources/mysql-connector-java.jar" to "/usr/share/java/"

and retry.

 

Make sure you use correct java path for the java version you are pointing too.

View solution in original post

12 REPLIES 12

avatar
Expert Contributor

Hi @Manoj690 

 

Can you share output of below commands -

 

  1. $ ls -ltr /usr/share/java/mysql.jar
  2. $find / -name mysql.jar
  3. $find / -name mysql-connector-java*.jar

avatar
Explorer

#ls -ltr /usr/share/java/mysql.jar
ls: cannot access '/usr/share/java/mysql.jar': No such file or directory

# find / -name mysql.jar
find: ‘/run/user/1000/doc’: Permission denied
find: ‘/run/user/1000/gvfs’: Permission denied

 

# find / -name mysql-connector-java*.jar
/usr/share/java/mysql-connector-java.jar
/var/lib/ambari-server/resources/mysql-connector-java.jar
find: ‘/run/user/1000/doc’: Permission denied
find: ‘/run/user/1000/gvfs’: Permission denied
/home/gaian/Downloads/mysql-connector-java.jar

avatar
Expert Contributor

Hi @Manoj690 

 

Can you copy - "/var/lib/ambari-server/resources/mysql-connector-java.jar" to "/usr/share/java/"

and retry.

 

Make sure you use correct java path for the java version you are pointing too.

avatar
Explorer
i did that but still show same error

#usr/jdk64/jdk1.8.0_112/bin/java -cp
/usr/lib/ambari-agent/DBConnectionVerification.jar:/usr/share/java/mysql-connector-java-5.1.37.jar
org.apache.ambari.server.DBConnectionVerification
"jdbc:mysql://xxxxx:3306/ambari" "ambari" "Password" com.mysql.jdbc.Driver
ERROR: Unable to connect to the DB. Please check DB connection properties.
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.

avatar
Expert Contributor

Hi @Manoj690 

 

Now the error is different -

 

"jdbc:mysql://xxxxx:3306/ambari" "ambari" "Password" com.mysql.jdbc.Driver
ERROR: Unable to connect to the DB. Please check DB connection properties.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications
link failure

 

Probably check connection to your DB server from ambari node.

Login to ambari server and telnet -

$telnet <DB_HOST>  3306

Make sure IPtables/selinux is disabled.

 

If you think initial issue is resolved please close this topic my accepting the correct reply on thread.

 

Will be happy to help you for above issue. Please keep posted.

avatar
Explorer

telnet is working but still shows same error ,,  iptables and selinux are disabled

avatar
Expert Contributor

From Ambari node can you try -

mysql -u <ambari_DB_username> <Ambari_DB_name> -h <DB_hostname> -P <Port>

 

Check if you are able to successfully login to the DB from ambari node.

 

 

avatar
Explorer
For localhost i am able to connect

for my host i am unable to connect

mysql -u ambari -p ambari -h xxxxxxxxxx -P 3306
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on 'xxxxxxxxx' (111)

avatar
Expert Contributor

@Manoj690  login to mysql and follow step 2 from below link

 

https://docs.cloudera.com/HDPDocuments/Ambari-2.7.3.0/administering-ambari/content/amb_using_ambari_...

 

make sure you give. permission as per your ambari hostname(FQDN) also.

avatar
Explorer

Again its getting the same error

#/usr/jdk64/jdk1.8.0_112/bin/java -cp
/usr/lib/ambari-agent/DBConnectionVerification.jar:/usr/share/java/mysql-connector-java-5.1.37.jar
org.apache.ambari.server.DBConnectionVerification "jdbc:mysql://
xxxxxxx:3306/ambari" "ambari" "xxxxx" com.mysql.jdbc.Driver
ERROR: Unable to connect to the DB. Please check DB connection properties.
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.




#ambari-server setup --jdbc-db=mysql
--jdbc-driver=/usr/share/java/mysql-connector-java-5.1.37.jar
Using python /usr/bin/python
Setup ambari-server
Copying /usr/share/java/mysql-connector-java-5.1.37.jar to
/var/lib/ambari-server/resources/mysql-connector-java-5.1.37.jar
Creating symlink
/var/lib/ambari-server/resources/mysql-connector-java-5.1.37.jar to
/var/lib/ambari-server/resources/mysql-connector-java.jar
If you are updating existing jdbc driver jar for mysql with
mysql-connector-java-5.1.37.jar. Please remove the old driver jar, from all
hosts. Restarting services that need the driver, will automatically copy
the new jar to the hosts.
JDBC driver was successfully initialized.
Ambari Server 'setup' completed successfully.

avatar
Expert Contributor

@Manoj690 

 

  1. Can you remove password from previous comment. Just to avoid escalation of security standards.
  2. Can you share the commands you executed previously?

avatar
Explorer

It gets error because i already created this user.

 
mysql> CREATE USER 'ambari'@'%' IDENTIFIED BY 'xxxxxxx';
ERROR 1396 (HY000): Operation CREATE USER failed for 'ambari'@'%'
mysql> GRANT ALL PRIVILEGES ON *.* TO 'ambari'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE USER 'ambari'@'localhost' IDENTIFIED BY 'xxxxxx';
ERROR 1396 (HY000): Operation CREATE USER failed for 'ambari'@'localhost'
mysql> GRANT ALL PRIVILEGES ON *.* TO 'xxxxxx'@'localhost';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> CREATE USER 'ambari'@'xxxxxx' IDENTIFIED BY 'xxxxxx';
ERROR 1396 (HY000): Operation CREATE USER failed for 'ambari'@'xxxxxxx'
mysql> GRANT ALL PRIVILEGES ON *.* TO 'ambari'@'xxxxxxx';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE USER 'ambari'@'%' IDENTIFIED BY 'xxxxxxxx';
ERROR 1396 (HY000): Operation CREATE USER failed for 'ambari'@'%'
mysql> GRANT ALL PRIVILEGES ON *.* TO 'ambari'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>
mysql> GRANT ALL PRIVILEGES ON *.* TO 'ambari'@'localhost';
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE USER 'ambari'@'xxxxx' IDENTIFIED BY 'xxxx';
ERROR 1396 (HY000): Operation CREATE USER failed for 'ambari'@'xxxxxx'
mysql> GRANT ALL PRIVILEGES ON *.* TO 'ambari'@'xxxxxxxx';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

Labels