Cannot connect Stash to MySQL database

Troubleshooting Databases

On this page

Still need help?

The Atlassian Community is here for you.

Ask the community

Symptoms

Stash fail to connect to MySQL database. The following appears in the atlassian-stash.log:

2012-11-27 21:38:56,806 INFO  [http-7990-5] 1298x15x1 1aan3w6 0:0:0:0:0:0:0:1%0 "POST /setup HTTP/1.1" c.a.s.i.m.DefaultMigrationService Setting up external database at jdbc:mysql://localhost:3306/stash131?autoReconnect=true&characterEncoding=utf8&useUnicode=true&sessionVariables=storage_engine%3DInnoDB
2012-11-27 21:39:01,305 WARN  [http-7990-5] 1298x15x1 1aan3w6 0:0:0:0:0:0:0:1%0 "POST /setup HTTP/1.1" c.a.s.i.m.DefaultMigrationService A connection could not be opened with the DataSource
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.6.0_37]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) ~[na:1.6.0_37]
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) ~[na:1.6.0_37]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:513) ~[na:1.6.0_37]
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) ~[mysql-connector-java-5.1.17.jar:na]
	at com.mysql.jdbc.Util.getInstance(Util.java:386) ~[mysql-connector-java-5.1.17.jar:na]
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013) ~[mysql-connector-java-5.1.17.jar:na]
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987) ~[mysql-connector-java-5.1.17.jar:na]
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982) ~[mysql-connector-java-5.1.17.jar:na]
...
Caused by: java.sql.SQLException: Unexpected exception encountered during query.
...
Caused by: java.lang.NullPointerException: null
	at com.mysql.jdbc.ConnectionImpl.getServerCharacterEncoding(ConnectionImpl.java:3100) ~[mysql-connector-java-5.1.17.jar:na]
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2095) ~[mysql-connector-java-5.1.17.jar:na]

Cause

This is a bug in MySQL driver 5.1.16 which causes an error in the connection when the JDBC URL has both "sessionVariables" and "characterEncoding" parameters at the same time (ie. url="jdbc:mysql://localhost:3306/stash131?autoReconnect=true&characterEncoding=utf8&useUnicode=true&sessionVariables=storage_engine%3DInnoDB")

Resolution

Upgrade to the latest MySQL driver version.

Tested to be working with MySQL driver 5.1.22

Last modified on Mar 30, 2016

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.