开发者社区 问答 正文

通过程序访问MySql

我通过我的客户端访问阿里云的mysql 是可以的、
但是程序却一直报

Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Access denied for user 'SliverZhang'@'180.165.211.225' (using password: YES)
### The error may exist in file [E:\JavaCode\SecKill\seckill\target\classes\mapper\SeckillDao.xml]
### The error may involve org.seckill.dao.SeckillDao.queryById
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Access denied for user 'SliverZhang'@'180.165.211.225' (using password: YES)
    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:122)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:113)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:73)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:386)
    ... 39 more
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Access denied for user 'SliverZhang'@'180.165.211.225' (using password: YES)
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
    at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:82)
    at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:68)
    at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:315)
    at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:75)
    at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:61)
    at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:303)
    at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:154)
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:102)
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:82)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:120)
    ... 46 more


我连我自己的本地数据库是好的。


阿里云的数据库需要做什么配置吗???

展开
收起
silver123 2018-01-07 19:15:53 3064 分享
分享
版权
举报
3 条回答
写回答
取消 提交回答
  • 回 楼主silver123的帖子





    兄弟,我添加了一个和我windows 一样的用户就好了,关键我配置文件还是root 啊,


    想不明白?。。

    -------------------------

    回 3楼silver123的帖子




    兄弟,我添加了一个和我windows 一样的用户就好了,关键我配置文件还是root 啊,

    -------------------------

    回 5楼dongshan8的帖子
    一样的

    -------------------------

    Re回 6楼silver123的帖子
    这是我的配置文件和报错信息
    2018-01-08 22:25:37 举报
    赞同 评论

    评论

    全部评论 (0)

    登录后可评论
  • 原3dmgame(三大妈)游戏网运维总监,原阿里云栖论坛版主,wlnmp一键安装包作者,多年互联网行业从业经验,专注于Linux平台的系统维护、DevOps运维实践、监控平台实践及应用部署。我的博客https://blog.whsir.com
    mysql没有设置权限,检查mysql用户权限和相应端口是否开放
    2018-01-08 10:47:19 举报
    赞同 评论

    评论

    全部评论 (0)

    登录后可评论
  • 旺旺:nectar2。
    版主回复:

    从报错信息来看,应该是权限相关的:
    SQLException: Access denied for user 'SliverZhang'@'180.165.211.225' (using password: YES)

    建议您检查一下mysql数据库的用户权限。

    -------------------------

    回 4楼(silver123) 的帖子
    版主回复:

    您从本地,用mysql连接工具成功连接到RDS的,与在java配置文件里填写的信息是一样的吗?如用户名之类的。

    -------------------------

    回 7楼(silver123) 的帖子
    版主回复:

    照图中的信息,有些奇怪喔。

    因为在java的jdbc.properties里,用户启是root,但在您的运行结果来看,使用的用户名是SliverZhang,两者不相同。

    在java的代码里还有其它的地方影响到运行时使用的mysql连接用户名吗?
    2018-01-08 10:15:12 举报
    赞同 评论

    评论

    全部评论 (0)

    登录后可评论