在最近重新格式化我的硬盘驱动器后,我无法使本地Java / Tomcat / MySQL堆栈正常工作.这是一个干净的MySQL安装,在Mac OSX 10.7.3(Lion)上运行.我得到的错误是当我的tomcat实例启动并尝试连接时:SEVERE: Servlet /c...
在最近重新格式化我的硬盘驱动器后,我无法使本地Java / Tomcat / MySQL堆栈正常工作.
这是一个干净的MySQL安装,在Mac OSX 10.7.3(Lion)上运行.
我得到的错误是当我的tomcat实例启动并尝试连接时:
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)
采取的步骤:
>我已经设置了concorde @ localhost的密码,如here和here所述
>我可以使用相同的凭据从控制台进行连接.以下所有工作:
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
>我已确保协调用户拥有权利 – 不仅来自localhost,而且还有任何地方:
GRANT ALL ON concorde.* TO 'concorde'@'%';
FLUSH PRIVELEDGES;
我错过了什么?
除此之外,我可以采取哪些步骤来弄清楚这里发生了什么?有没有我可以检查的日志?
编辑
根据要求,这是我正在使用的代码.
但是,在重新格式化我的硬盘驱动器之前,这段代码工作正常,所以我怀疑问题在于它.
该应用程序在一个弹簧容器中运行,并且在Spring的启动期间,事情已经结束了.
以下是相关的bean声明:
<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>
而且,这里是定义的属性:
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
database.name=concorde
database.username=concorde
database.password=password
database.host=localhost
database.port=3306
此外,这里是权限查询的(删节)输出:
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 |
+----------------------------------------+---------------+-------------------------+--------------+
注意 – 这是通过使用root登录来运行的.
我怀疑在那里为我的用户显示的NO有一个线索,但我不确定如何解释这些数据.
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 |
解决方法:
由于您似乎可以使用命令行中的预期凭据登录,因此我怀疑您的属性是否正确地替换为“dataSource”bean.
尝试暂时硬编码dataSource bean的所有参数.
如果可行,则不会设置您的属性.
本文标题为:java – MySQL:用户拒绝访问…使用密码:YES
基础教程推荐
- 基于Springboot的漫画网站平台设计与实现 2023-03-22
- Spring中bean集合注入的方法详解 2023-02-19
- 详解使用JavaMailSender给曾经心爱的她再中秋发送一封特别的邮件 2023-05-14
- Java实现双向链表 2022-11-08
- Java操作FTP实现上传下载功能 2023-06-30
- Java Optional的判空操作详解 2023-06-06
- java性能优化之分代回收 2023-02-20
- SpringMVC Restful风格与中文乱码问题解决方案介绍 2023-06-10
- springboot+mybatis拦截器方法实现水平分表操作 2023-04-07
- java后端合成图片的实现示例 2023-01-09