Looks like you are using MySQL as Non Default Database for your AmbariServer.
So i am sure that you might have already performed the steps mentioned in the doc:
It will be good to verify few things:
### Checks from MySQL host side: ###
1. On the MySQL Database host please verify if the MySQL Database is running fine and the port "3306" is listening?
# netstat -tnlpa | grep 3306
NOTE: please take a look at your MySQL DB configs "/etc/my.cnf" to be double sure that it is configured to listen to 3306 port (default port) or configured to listen to some all interfaces and if it is using any other port?
You can find the ports your mysql is listening to by passing the MySQL DB PID to the following command:
# netstat -tnlpa | grep $MYSQL_PID
2. On the MySQL Database host please verify if the "firewall" /"iptables" is disabled so that from the Hive Metastore host the Postgres Post can be accessed.
# systemctl status firewalld
# service iptables status
If iptables/firewalld is enabled then please make sure to allow MySQL DB port access from remote hosts (OR) disable it.
### Checks from AmbariServer host side: ###
3. From AmbariServer host please get the configured DB details (to verify if you are using correct MySQL host & port inside ambari.properties) ?
# grep 'jdbc' /etc/ambari-server/conf/ambari.properties
4. Once the host & port of DB is verified to be correctly configured as above then please try to connect to MySQL host & port using telnet / netcat utilities. This will help us in isolating any Network / Port / Hostname issues. To verify whether the MySQL DB host & port to verify if at the network level the port is accessible ?
# telnet $MYSQL_DB_HOSTNAME 3306
# nv -v $MySQL_DB_HOSTNAME 3306
5. From Ambari Server host please verify if you are using correct "mysql-connector-java.jar" driver JAR of correct version? (based on your MySQL version).
6. Please try to use the same connector JAR to establish the connection to MySQL DB from ambari server host using the following DB Connection checker utility to see if the db connection can be established.
# /usr/jdk64/jdk1.8.0_112/bin/java -cp /usr/lib/ambari-server/resources/DBConnectionVerification.jar:/usr/share/java/mysql-connector-java.jar org.apache.ambari.server.DBConnectionVerification "jdbc:mysql://XXXXXXXXXXX/ambari" "ambari" "bigdata" com.mysql.jdbc.Driver
Please change the MySQL DB URL / username and password based on your "ambari.properties" DB connection settings.
If Still we see Failure:
If everything is fine still you are getting the error establishing connection to MySQL from AmbariServer. then please share the output of the above command along with the following details:
1. /var/log/ambari-server/ambari-server.log ----> We would like to see Full error from starting including the StackTrace.
2. Please try to restart MySQL Database once and notice if you see any error in MySQL DB logs?
Please also share the DB log and "/etc/my.cnf"
If above update helps in finding the answer to your issue then, Please make sure to mark the answer as the accepted solution.
If you find a reply useful, say thanks by clicking on the thumbs up button.