云笔记项目-测试时无法连接MySQL Server
事情起因:用Mac提交云笔记项目到SVN后,使用台式机import SVN上的云笔记代码,发现到了台式机上,进行junit测试时无法连接Mysql数据库服务器,而Mac上是可以的。以下是报警内容和报警画面
测试连接失败画面:

报警内容:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server.)
### The error may exist in file [F:\workspace\Cloud_Note_Clyang\target\classes\Mapper\NoteMapper.xml]
### The error may involve com.boe.Dao.NoteDAO.findNoteByNoteBookId
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server.)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
at com.sun.proxy.$Proxy19.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:128)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:68)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
at com.sun.proxy.$Proxy22.findNoteByNoteBookId(Unknown Source)
at Test.testNoteDAO.test(testNoteDAO.java:25)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
以下略...
分析解决:
通过报警内容,发现报“org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection”,“Cannot create PoolableConnectionFactory (Could not create connection to database server.)“
(1)发现报警不能连接MySQL服务器,网上也有类似的问题,他们是通过修改mysql数据库里user表的方法,参考博客 https://blog.csdn.net/qq_41675973/article/details/84898061
修改mysql库的user表,将host项,从localhost改为%。%这里表示的是允许任意host访问,如果只允许某一个ip访问,则可改为相应的ip,比如可以将localhost改为192.168.1.123,这表示只允许局域网的192.168.1.123这个ip远程访问mysql。
mysql> use mysql;
mysql> update user set host = ‘%’ where user = ‘root’;
mysql> select host, user from user;
mysql> flush privileges;
(2)另外一种是Mysql连接驱动包的问题
通过对比发现,Mac上Mysql的版本为5.7,驱动版本5.1.34,而台式机上Mysql的版本为8.0,驱动也为5.1.34,尝试将驱动从5.1.34更新为最新的5.1.46
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
</dependency>
更新后的驱动

重新进行测试连接:

发现可以通过笔记ID来查找到笔记Body内容,测试OK,原因为更换电脑后,Mysql版本更换,驱动包也需要随着更换。
云笔记项目-测试时无法连接MySQL Server的更多相关文章
- ems lite 客户端远程连接mysql server
在本地用ems客户端远程连接虚拟机上的mysql server,弹出客户端没有权限访问mysql server.使用下面方法进行设置:mysql> select host,user,passwo ...
- 使用什么工具连接MySQL Server
字符界面:命令行终端(需MySQL Client) GUI界面:Navicat.MySQL Workbench 开发语言:使用相应语言的MySQL数据库驱动包或模块连接MySQL 我一般用的是命令行, ...
- Java通过mysql-connector-java-8.0.11连接MySQL Server 8.0遇到的几个问题
这次新安装了一个MySQL数据库,然后navicat连接数据库一点问题没有. 但是通过Java的jdbc连接却怎么都建立不了连接. 报如下错: 网上找了很久找到了原因: 数据库用的是Mysql8版本, ...
- VS2017项目中使用代码连接MySQL数据库,以及进行数据添加
//头文件 #include "mysql.h" //函数定义 // 执行sql语句, 包括增加.删除.更新数据 bool ExecuteSql(MYSQL m_mysql,con ...
- Android真机测试时无法连接服务器
之前服务器的通信一直是在模拟机上实现的,今天用在真机上却不成功.百度之后发现是安卓9以后禁止使用HTTP直接访问服务器.记录一下以后使用. 参考博文:https://blog.csdn.net/don ...
- 数据库导入时出现“2006 - MySQL server has gone away”问题的解决(windows)
1.查到文件my.ini,在文件最后([mysqld]段最后),修改"max_allowed_packet = 50M",添加"interactive_timeout = ...
- 用msi安装MySQL时MySQL Server组件不能安装,或安装失败
我的环境: MySQL8.0.15, win10 错误描述:在安装MySQL时,如果MySQL Server组件提示不能安装,错误提示是:VS 2015没有安装或安装失败.原因 ...
- 用EntityFramework6连接MySQL【转】
http://www.cnblogs.com/wujingtao/p/5399950.html 不是微软的亲儿子这待遇就是不一样,其中的坑可真实不少,第一次连MySQL足足折腾了我大半天. 废话不多说 ...
- 使用EntityFramework6连接MySQL
使用EntityFramework6连接MySQL 不是微软的亲儿子这待遇就是不一样,其中的坑可真实不少,第一次连MySQL足足折腾了我大半天. 废话不多说直接开始. 安装MySQL 从官网上下载最新 ...
随机推荐
- vue项目,npm install后,npm run dev报错问题
报错: ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! metools@1.0.0 dev: `node build/dev-server.js` npm ...
- day2----python的基本类型
本文档的大致内容:(python使用版本3.6.4) 1 数字--int 2 布尔--bool 3 字符串--str 4 元祖--() 5 列表---['a','b'] 6 字典--{} 运算符: ...
- C#面向对象基础2
一.属性 作用:保护字段,对字段的赋值取值进行限定 意思是在初始化对象的时候防止出现不是事实的违规操作 如将性别赋值为‘中’ 本质:两个方法 get方法和set方法. p ...
- laravel 的 intervention-image 图像处理笔记
安装: https://blog.csdn.net/beyond__devil/article/details/62230610 需求: PHP >= 5.4 Fileinfo 扩展 GD库 & ...
- spring 之 depends-check
我们知道 spring xml 配置中 bean 的子元素 property 是按照 setXxx(SomeType someParam) 方式来设值的,换句话说, 是根据属性的setter 方法, ...
- nohup php -f xx.php &
nohup php -f xx.php &
- as2 shareObject本地缓存存储位置:
shareObject本地缓存存储位置: win7系统用户到C:\Users\[你的用户名]\AppData\Roaming\Macromedia\Flash Player\#SharedObject ...
- linux集群时间同步搭建
http://xstarcd.github.io/wiki/sysadmin/ntpd.html http://www.voidcn.com/blog/xuxudede1989/article/p-4 ...
- 尚硅谷springboot学习11-占位符
1.随机数 2.占位符获取之前配置的值,如果没有可以使用:指定默认值
- 尚硅谷springboot学习10-@PropertySource,@ImportResource,@Bean
@PropertySource 使用指定的属性文件而不一定是application.xxx 同样可以注入相关内容 @ImportResource 导入Spring的配置文件,让配置文件里面的内容生效: ...