Cannot create PoolableConnectionFactory on jenkins - mysql

I am using Sonarqube with MySql. I have Jenkins in place and I would like to integrate Sonar runner with TC for differents projects mainly (Java, PHP). I have done following :
Download sonar zip (last version) in windows plateform.
StartSonar.bat
I have a MySQL in CentOS in Remote VM :
I connect to remote MySQL using Cygwin ssh:
then I create a schema, as follow :
MySQL:
CREATE DATABASE sonar CHARACTER SET UTF8;
CREATE USER 'sonar'#'*' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'#'*';
FLUSH PRIVILEGES;
Then I disabled the VM firewall with : sudo systemctl stop firewalld
When I start my sonar with StartSonar.bat, I have the following error:
Stacktrace:
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'sonar'#'10.1.162.61' (using password: YES))
at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549) ~[commons-dbcp-1.4.jar:1.4]
at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388) ~[commons-dbcp-1.4.jar:1.4]
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044) ~[commons-dbcp-1.4.jar:1.4]
at org.sonar.core.persistence.DefaultDatabase.checkConnection(DefaultDatabase.java:115) ~[sonar-core-5.1.2.jar:na]
... 28 common frames omitted
Caused by: java.sql.SQLException: Access denied for user 'sonar'#'10.1.162.61' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996) ~[mysql-connector-java-5.1.34.jar:5.1.34]
What am I missing here, please ?

The solution is to enable sonar credentials in sonar.properties in conf folder as follow :
# User credentials.
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
#----- MySQL 5.x
# Only InnoDB storage engine is supported (not myISAM).
# Only the bundled driver is supported.
sonar.jdbc.url=jdbc:mysql://10.1.163.103:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance

Related

TALEND - Vagrant Mysql connexion issues

I'm pulling my hair over the following situation.
I'm unable to connect to my MySQL server in Vagrant (2.0.0 , OS: Ubuntu 16.04 ) with only specific applications (HeidiSQL and Talend 6.1).
This error happens with Talend MySQL components with the mysql-connector-java-5.1.30 jar and Java 1.8 JRE.
I receive the following error each time when connecting either directly (TCP/IP) or over SSH (TCP/IP over SSH) to the MySQL Server with the aforementionned applications:
Access denied for user 'user'#'IP' (using password: YES)
This however doesn't happens with MysqlWorkbench with both direct connection (TCP/IP) or over SSH with the same user credentials. Below are the settings of the MySQL server:
MySQL Server Network Info
Maria Db: 10.0.34
bind-address: 0.0.0.0
skip-name-resolve: true
The following have already been tried and tested:
Access credentials and privileges verification
DNS flush both on Guest and Host machines
Addition of MySQL server IP to host file
Verification of ports opening both on host and guest
The following solved the issue:
GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'#'%' WITH **GRANT OPTION**;
The GRANT OPTION does the trick.
Alternatively this could be caused by wrong driver being used in your Talend workspace. To update the MySQL connector JAR follow the steps below:
Donwload the updated connector driver here
Replace the 'tMySQLOutput/tMySQLInput' component(s) with an equivalent tJDBC ones
Add the new connector JAR (No 2 on the image) and the class name com.mysql.jdbc.Driver (No 4 on the image) (ref https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-installing-classpath.html)

SonarQube analysis via Maven fails with database access denied to MySQL

I have instances of MySQL, SonarQube, and TeamCity all running on the same Linux host. All are very vanilla installations (out of the box / insecure / local / behind company firewall).
These are my Maven settings ... where ${fullyQualifiedDomainName} is something like build.company.com
<profile>
<id>env-dev</id>
<properties>
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
<sonar.jdbc.url>jdbc:mysql://${fullyQualifiedDomainName}:3306/sonar?useUnicode=true&characterEncoding=utf8</sonar.jdbc.url>
<sonar.jdbc.username>sonar</sonar.jdbc.username>
<sonar.jdbc.password>sonar</sonar.jdbc.password>
<sonar.host.url>http://${fullyQualifiedDomainName}:9000</sonar.host.url>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
I run the command mvn sonar:sonar to perform and upload SonarQube analysis.
The Maven settings above work OK from my Windows PC. However, if I run from the Linux server via TeamCity, I see this error: (giant Java stacktrace + ...):
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.5:sonar (default-cli) on project IMQuant:
Fail to connect to database:
Cannot create PoolableConnectionFactory
(Access denied for user 'sonar'#'${fullyQualifiedDomainName}'
(using password: YES)) -> [Help 1]
If I switch to use localhost in the Maven settings it runs OK on the Linux server. I am guessing this is one of the following issues:
MySQL config (I am a MySQL newbie)
Linux server config (network config / admin stuff beyond my control)
MySQL JDBC driver bug (localhost != fqdn from localhost)
For now I am using a second Maven profile in my settings for TeamCity / Linux with localhost.
Is there a solution for this issue? Has anyone seen this issue?
Update
Here are the commands to create my MySQL database for SonarQube. As noted by #Mithfindel, it may be the root cause.
CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'sonar' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'#'%' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'#'localhost' IDENTIFIED BY 'sonar';
FLUSH PRIVILEGES;
Ref: https://github.com/SonarSource/sonar-examples/blob/master/scripts/database/mysql/create_database.sql
It looks like a MySQL configuration issue: for MySQL, a GRANT on localhost is different from a GRANT on localhost's FQDN. You might want to check which permissions are granted to users 'sonar'#'localhost' and 'sonar'#'fqdn-of-localhost' or 'sonar'#'%'.

Failed to connect to MySQL at 127.0.0.1

Regarding the first answer to the Question Failed to connect to mysql at 127.0.0.1:3306 with user root access denied for user 'root'#'localhost'(using password:YES), after step 3, says if connection is denied then type
mysql >GRANT ALL ON [DatabaseName].* TO 'root'#'127.0.0.1' IDENTIFIED BY '[PASSWORD]';
But when i type the following in command prompt of Windows,
C:\Program Files\MySQL\MySQL Server 5.6\bin>GRANT ALL ON MySQL Server 5.6.* TO'root'#'127.0.0.1' IDENTIFIED BY '[password]';
I get the following error.
'GRANT' is not recognized as an internal or external command,operable program or batch file.
Please help as I'm trying to establish the connection between MySQL and the Database.

Sonar SQLException when starting tomcat

I have been trying to install a new version of Sonar, however after this did not work (due to a table_lock error with the database migration) I have referred back to the original version 2.11. Now when I start tomcat I get this exception (attached). I have been changing the my.cnf and some things may have been reset.
In the catalina.out log I get this error:
... 42 common frames omitted
Caused by: java.sql.SQLException: Access denied for user 'sonar'#'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075) [mysql-connector-java-5.1.13.jar:na]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566) [mysql-connector-java-5.1.13.jar:na]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498) [mysql-connector-java-5.1.13.jar:na]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919) [mysql-connector-java-5.1.13.jar:na]
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4004) [mysql-connector-java-5.1.13.jar:na]
Looks like your Sonar database no longer has access granted for the sonar user. To fix it, type "mysql" from a command prompt and do the following:
mysql> GRANT ALL ON your_sonar_database TO 'sonar#localhost' IDENTIFIED BY 'password_for_sonar_user';
mysql> FLUSH PRIVILEGES;
mysql> exit
Then restart the Sonar server and you should be good.

Unable to access Sonar MySQL database Caused by: java.sql.SQLException: Access denied for user 'sonar'#'glassfishdev.ccs.local' (using password: YES)

I am trying to add Sonar to my Continuous Integration build system. I am using ANT as my build script and I am using the sonar-ant-task-1.1.jar for sonar to generate the reports based on my source code in SVN.
Problem
When the build runs and hits the sonar ant task I get the exception as follows:
Caused by: java.sql.SQLException: Access denied for user 'sonar'#'glassfishdev.ccs.local' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4004)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1284)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2312)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289)
at org.sonar.jpa.session.DriverProxy.connect(DriverDatabaseConnector.java:160)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at org.sonar.jpa.session.DriverDatabaseConnector.getConnection(DriverDatabaseConnector.java:95)
at org.sonar.jpa.session.AbstractDatabaseConnector.testConnection(AbstractDatabaseConnector.java:185)
... 40 more
What I have done
1. Install MySQL database.
2. Create the sonar database, sonar user, and grant permissions by using the script provided in the sonar installation
**CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'sonar' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'#'%' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'#'localhost' IDENTIFIED BY 'sonar';
FLUSH PRIVILEGES;**
3. Added the following to my build script
4. Added the following external variables in Jenkins Freestyle build project
sonar.jdbc.url=jdbc:mysql://10.120.21.12:3306/sonar?useUnicode=true&characterEncoding=utf8
sonar.jdbc.driverClassName=com.mysql.jdbc.Driver
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.host.url=http://10.120.21.12:9000/
5. I was also available to connect to the database through my sql client tool to verify that the database, user and permissions statements were executed correctly.
However when Jenkins runs the build it does not seem to know how to connect to the MySQL database.
Any thoughts?
The solution was to run the following command:
GRANT ALL ON *.* TO 'sonar'#'%';
The right solution is this:
GRANT ALL PRIVILEGES ON `sonar`.* TO 'sonar'#'localhost';
As explained here, connections to localhost occur over a UNIX domain socket. You are likely logging in as an anonymous user to localhost (e.g. ''#localhost).
I just tried it with sonar 4.5.2 with grants only on sonar.* and its definitely not working.
It looks like sonarqube requires additionnal privileges to work, personnaly i haven't identified which ones yet, and i'm still using a grant all on the database.