5

Having recently reformatted my hard-drive, I cannot get my local Java/Tomcat/MySQL stack working.

This is a clean MySQL install, running on Mac OSX 10.7.3 (Lion).

The error I'm getting is when my tomcat instance starts up and tries to connect is:

SEVERE: Servlet /concorde-web threw load() exception
java.sql.SQLException: Access denied for user 'concorde'@'localhost' (using password: YES)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)

Steps taken:

  • I've set concorde@localhost's password as described here and here
  • I can connect from the console using the same credentials. All of the following work:

    mysql -u concorde -h localhost -p
    mysql -u concorde -p
    mysql -u concorde -h localhost -D concorde -p
    // the app is trying to connect as user concorde to db concorde
    
  • I've ensured that the concorde user has rights - not just from localhost, but anywhere:

    GRANT ALL ON concorde.* TO 'concorde'@'%';
    FLUSH PRIVELEDGES;
    

What am I missing?

Beyond that, what steps can I take to work out what's going on here? Are there any logs I can check?

EDIT

As requested, here's the code I'm using.

However, this code worked fine before reformatting my hard-drive, so I'm doubtful that the problem lies within it.

The app is running in a spring container, and it's during Spring's startup that things are faling over.

Here are the relevant bean declarations:

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="persistenceUnitName" value="spring-jpa" />
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="showSql" value="true" />
            <property name="generateDdl" value="false" />
            <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
        </bean>
    </property>
</bean>


<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url"
        value="jdbc:mysql://${database.host}:${database.port}/${database.name}" />
    <property name="username" value="${database.username}" />
    <property name="password" value="${database.password}" />
    <property name="initialSize" value="5" />
    <property name="maxActive" value="50" />
</bean>

And, here are the defined properties:

hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
database.name=concorde
database.username=concorde
database.password=password  
database.host=localhost
database.port=3306

Additionally here is the (abridged) output of a query on the permissions:

mysql> select * from information_schema.user_privileges;

| 'concorde'@'localhost'                 | def           | USAGE                   | NO           |
| ''@'localhost'                         | def           | USAGE                   | NO           |
| ''@'Marty-Pitts-MacBook-Pro.local'     | def           | USAGE                   | NO           |
| 'concorde'@'%'                         | def           | USAGE                   | NO           |
+----------------------------------------+---------------+-------------------------+--------------+

Note - this was run by logging on with root.

I suspect there's a clue in the NO shown there for my user, but I'm not sure how to interpret that data.

mysql> select * from information_schema.SCHEMA_PRIVILEGES;
+------------------------+---------------+--------------+-------------------------+--------------+
| GRANTEE                | TABLE_CATALOG | TABLE_SCHEMA | PRIVILEGE_TYPE          | IS_GRANTABLE |
+------------------------+---------------+--------------+-------------------------+--------------+
| 'concorde'@'localhost' | def           | concorde     | SELECT                  | YES          |
| 'concorde'@'localhost' | def           | concorde     | INSERT                  | YES          |
| 'concorde'@'localhost' | def           | concorde     | UPDATE                  | YES          |
| 'concorde'@'localhost' | def           | concorde     | DELETE                  | YES          |
| 'concorde'@'localhost' | def           | concorde     | CREATE                  | YES          |
| 'concorde'@'localhost' | def           | concorde     | DROP                    | YES          |
| 'concorde'@'localhost' | def           | concorde     | REFERENCES              | YES          |
| 'concorde'@'localhost' | def           | concorde     | INDEX                   | YES          |
| 'concorde'@'localhost' | def           | concorde     | ALTER                   | YES          |
| 'concorde'@'localhost' | def           | concorde     | CREATE TEMPORARY TABLES | YES          |
| 'concorde'@'localhost' | def           | concorde     | LOCK TABLES             | YES          |
| 'concorde'@'localhost' | def           | concorde     | EXECUTE                 | YES          |
| 'concorde'@'localhost' | def           | concorde     | CREATE VIEW             | YES          |
| 'concorde'@'localhost' | def           | concorde     | SHOW VIEW               | YES          |
| 'concorde'@'localhost' | def           | concorde     | CREATE ROUTINE          | YES          |
| 'concorde'@'localhost' | def           | concorde     | ALTER ROUTINE           | YES          |
| 'concorde'@'localhost' | def           | concorde     | EVENT                   | YES          |
| 'concorde'@'localhost' | def           | concorde     | TRIGGER                 | YES          |
| 'concorde'@'%'         | def           | concorde     | SELECT                  | NO           |
| 'concorde'@'%'         | def           | concorde     | INSERT                  | NO           |
| 'concorde'@'%'         | def           | concorde     | UPDATE                  | NO           |
| 'concorde'@'%'         | def           | concorde     | DELETE                  | NO           |
| 'concorde'@'%'         | def           | concorde     | CREATE                  | NO           |
| 'concorde'@'%'         | def           | concorde     | DROP                    | NO           |
| 'concorde'@'%'         | def           | concorde     | REFERENCES              | NO           |
| 'concorde'@'%'         | def           | concorde     | INDEX                   | NO           |
| 'concorde'@'%'         | def           | concorde     | ALTER                   | NO           |
| 'concorde'@'%'         | def           | concorde     | CREATE TEMPORARY TABLES | NO           |
| 'concorde'@'%'         | def           | concorde     | LOCK TABLES             | NO           |
| 'concorde'@'%'         | def           | concorde     | EXECUTE                 | NO           |
| 'concorde'@'%'         | def           | concorde     | CREATE VIEW             | NO           |
| 'concorde'@'%'         | def           | concorde     | SHOW VIEW               | NO           |
| 'concorde'@'%'         | def           | concorde     | CREATE ROUTINE          | NO           |
| 'concorde'@'%'         | def           | concorde     | ALTER ROUTINE           | NO           |
| 'concorde'@'%'         | def           | concorde     | EVENT                   | NO           |
| 'concorde'@'%'         | def           | concorde     | TRIGGER                 | NO           |
Community
  • 1
  • 1
Marty Pitt
  • 28,822
  • 36
  • 122
  • 195
  • My MySQL error log is in `mysql/data/mysql_error.log`. Check it out (file name may be a little different), you may find more details there (although I doubt it...). Can you provide the piece of code where you attempt to connect ? – Radu Murzea Feb 16 '12 at 21:35
  • Is your jdbc url is in correct format ? – Sajan Chandran Feb 16 '12 at 21:42
  • My best guess is you have your parameters reversed in your java code somehow, please post the code. – Radu Murzea Feb 16 '12 at 21:44
  • can you try to connect using this command? `mysql -u concorde -h 127.0.0.7 -p` – Dan Soap Feb 16 '12 at 22:24
  • I know very little about what you are talking about, but I noticed on http://dev.mysql.com/doc/refman/5.1/en/connector-j-usagenotes-spring-config.html that they are using a different class (org.springframework.jdbc.datasource.DriverManagerDataSource) for the DataSource. Sorry if it isn't relevant, just wanted to read up on the issue and noticed it. – Poodlehat Feb 16 '12 at 22:26
  • @Cassy I assume you meant `127.0.0.1`? If so, then I just tried, and that connected fine. – Marty Pitt Feb 16 '12 at 22:26
  • @MartyPitt: yes, that's what I meant. Did you also check, if there are different right definitions for different user/host combinations? `concorde@127.0.0.1`, `concorde@%`, `concorde@localhost` ? – Dan Soap Feb 16 '12 at 22:35
  • @Cassy - I've done a `GRANT ALL ON concorde.* TO 'concorde'@'%';`. Is that sufficient? (And, is the syntax correct?) – Marty Pitt Feb 16 '12 at 22:37
  • @MartyPitt: Yes, the syntax is correct. However, if there's a different definition for `concorde@localhost`, that might be used instead of the one you've give. Check the output of `select * from SCHEMA_PRIVILEGES` and see if there's anything weird looking. – Dan Soap Feb 16 '12 at 22:42
  • @Cassy ACtually, yeah, something does look a bit weird there -- I've updated the post with the results - but I see my user has only a small subset of priveledges, despite running `GRANT ALL...`. Is there something in this? – Marty Pitt Feb 16 '12 at 22:55
  • @MartyPitt: Sorry, I've changed my edit above after you ran the statement. Could you plz add the output for `select * from information_schema.SCHEMA_PRIVILEGES`? – Dan Soap Feb 16 '12 at 22:56
  • @Cassy - Updated as requested – Marty Pitt Feb 16 '12 at 23:03
  • @MartyPitt: Looks fine to me ... Privileges then don't seem to be the issue here. Did you double check the passwords you used in the properties file and on the command line? – Dan Soap Feb 16 '12 at 23:09
  • @Cassy Yes. I've also tried connecting with `root` (various combinations of it), and reset the password for `concorde` several times. – Marty Pitt Feb 16 '12 at 23:11
  • Perhaps one application is IPv6-aware, and system has incorrect reverse DNS. Try `mysql -h ::1` and see if *that* works... – Borealid Feb 16 '12 at 23:52
  • I had working Java<-->MySQL 5.5 code break immediately following my upgrade from 10.7.2 to 10.7.3. I tried numerous troubleshooting steps, including full reinstall of new MySQL. The only way I eventually got my code working again was to install MySQL 5.6. After doing this, everything just worked again. It's worth noting that the MySQL downloads for OS X only state they are compatible with 10.6. It is entirely possible there is an incompatibility in 10.7.3 and you need to upgrade MySQL versions. – Daniel Widdis Feb 18 '12 at 04:26

2 Answers2

3

Since it appears that you can log in with the expected credentials from the command line, I'd be suspicious of whether your properties are being properly substituted into your 'dataSource' bean.

Try temporarily hard-coding all of the parameters for the dataSource bean. If that works, then your properties aren't being set.

GreyBeardedGeek
  • 29,460
  • 2
  • 47
  • 67
2

Somewhat embarrasingly, the answer turned out to be that the password is being read in from an external file.

Someone else checked out the file, and when committing it, some trailing whitespace characters got appended to the password. It seems that these aren't trimmed when spring reads the property file (reasonable, I guess).

However, this is what was causing the issue. A genuine wrong password.

Marty Pitt
  • 28,822
  • 36
  • 122
  • 195
  • Wrestled a day with this before read this post. Had a linebreak there. Syncing between two computers caused it somehow. – Gjordis Feb 12 '14 at 20:49
  • I had a similar error. After reading this answer i hardly noticed, due to the particular font of the server, that in the configuration the password was written with a '1' instead of an 'l' – P. Vucinic Oct 23 '20 at 14:43