SpringBoot项目报错:java.sql.SQLSyntaxErrorException: Unknown database ‘mscode‘

一、错误描述

date:2020-08-09 10:34:16	thread:Druid-ConnectionPool-Create-1976547672	level:ERROR	logger:com.alibaba.druid.pool.DruidDataSource          	msg:create connection SQLException, url: jdbc:mysql://127.0.0.1:3306/mscode?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8, errorCode 1049, state 42000
java.sql.SQLSyntaxErrorException: Unknown database 'mscode'
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)
	at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1643)
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1709)
	at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2715)

二、引起错误的原因

原本电脑上面就有mysql,然后再运行springBoot项目的时候,需要运行一个mysql的bat文件,项目中mysql的端口号被占用
在这里插入图片描述
三、解决方案
停止原来安装的mysql服务,把端口号留给项目需要的mysql服务

1、以管理员身份运行cmd,输入net stop mysql
在这里插入图片描述
2、重新运行项目的mysql的bat文件,重新启动项目
在这里插入图片描述
在这里插入图片描述
3、在运行完毕之后,建议重新启动本机的mysql服务,避免在下次使用本机的mysql服务时产生错误。
注:在cmd中输入 net start mysql即可
在这里插入图片描述

21:52:18.428 [Thread-0] DEBUG org.springframework.boot.devtools.restart.classloader.RestartClassLoader - Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@3410cfae . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.7.0) 2025-06-11 21:52:19.426 INFO [,,] 23176 --- [ restartedMain] com.hospital.LxjApplication : Starting LxjApplication using Java 19 on DESKTOP-1QAH2DU with PID 23176 (E:\2025年文件\医疗系统\hospital_infront\target\classes started by dell in E:\2025年文件\医疗系统\hospital_infront) 2025-06-11 21:52:19.427 INFO [,,] 23176 --- [ restartedMain] com.hospital.LxjApplication : No active profile set, falling back to 1 default profile: "default" 2025-06-11 21:52:19.473 INFO [,,] 23176 --- [ restartedMain] o.s.c.c.c.ConfigServerConfigDataLoader : Fetching config from server at : http://localhost:8888 2025-06-11 21:52:19.473 INFO [,,] 23176 --- [ restartedMain] o.s.c.c.c.ConfigServerConfigDataLoader : Connect Timeout Exception on Url - http://localhost:8888. Will be trying the next url if available 2025-06-11 21:52:19.473 WARN [,,] 23176 --- [ restartedMain] o.s.c.c.c.ConfigServerConfigDataLoader : Could not locate PropertySource ([ConfigServerConfigDataResource@2941e75 uris = array<String>['http://localhost:8888'], optional = true, profiles = list['default']]): I/O error on GET request for "http://localhost:8888/application/default": Connection refused: no further information; nested exception is java.net.ConnectException: Connection refused: no further information 2025-06-11 21:52:19.474 INFO [,,] 23176 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable 2025-06-11 21:52:19.474 INFO [,,] 23176 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG' 2025-06-11 21:52:20.168 INFO [,,] 23176 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode. 2025-06-11 21:52:20.344 INFO [,,] 23176 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 169 ms. Found 10 JPA repository interfaces. 2025-06-11 21:52:20.934 INFO [,,] 23176 --- [ restartedMain] o.s.cloud.context.scope.GenericScope : BeanFactory id=0d55cccc-710b-3b96-99af-97eae531b364 2025-06-11 21:52:21.751 INFO [,,] 23176 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2025-06-11 21:52:21.761 INFO [,,] 23176 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2025-06-11 21:52:21.761 INFO [,,] 23176 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.63] 2025-06-11 21:52:21.850 INFO [,,] 23176 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2025-06-11 21:52:21.851 INFO [,,] 23176 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2376 ms 2025-06-11 21:52:22.211 INFO [,,] 23176 --- [ restartedMain] c.a.d.s.b.a.DruidDataSourceAutoConfigure : Init DruidDataSource 2025-06-11 21:52:22.388 INFO [,,] 23176 --- [ restartedMain] com.alibaba.druid.pool.DruidDataSource : {dataSource-1} inited 2025-06-11 21:52:22.662 ERROR [,,] 23176 --- [eate-1539298006] com.alibaba.druid.pool.DruidDataSource : create connection SQLException, url: jdbc:mysql://localhost:3306/hosp_infront?serverTimezone=UTC&&characterEncoding=utf-8, errorCode 1049, state 42000 java.sql.SQLSyntaxErrorException: Unknown database 'hosp_infront' at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.28.jar:8.0.28] at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.28.jar:8.0.28] at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:829) ~[mysql-connector-java-8.0.28.jar:8.0.28] at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:449) ~[mysql-connector-java-8.0.28.jar:8.0.28] at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:242) ~[mysql-connector-java-8.0.28.jar:8.0.28] at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198) ~[mysql-connector-java-8.0.28.jar:8.0.28] at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:149) ~[druid-1.1.9.jar:1.1.9] at com.alibaba.druid.filter.stat.StatFilter.connection_connect(StatFilter.java:218) ~[druid-1.1.9.jar:1.1.9] at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:143) ~[druid-1.1.9.jar:1.1.9] at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1515) ~[druid-1.1.9.jar:1.1.9] at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1578) ~[druid-1.1.9.jar:1.1.9] at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2466) ~[druid-1.1.9.jar:1.1.9] 2025-06-11 21:52:22.677 ERROR [,,] 23176 --- [eate-1539298006] com.alibaba.druid.pool.DruidDataSource : create connection SQLException, url: jdbc:mysql://localhost:3306/hosp_infront?serverTimezone=UTC&&characterEncoding=utf-8, errorCode 1049, state 42000 java.sql.SQLSyntaxErrorException: Unknown database 'hosp_infront'
最新发布
06-12
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值