时隔两年多了,已经很久没发过博客了。这次就更新一版,云数据库mysql常见问题的博客。
最近一个月自己经历了,本地服务器、云服务器的搭建,包括但不限于云数据库的购买、域名申请、证书申请、域名备案、nginx配置、mysql配置等流程,正儿八经把服务器部署的流程都走了一遍。
这里简单举几个本地服务器上mysql正常,但在云服务器上MySQL异常的错误吧!
问题1. 提示“required a bean of type 'xxx' that could not be found”之类的问题:
这个问题,有可能是你的Spring工程的数据库配置写在了application.propertie文件里,虽然本地服务器生效,但是云服务器部署时候连服务都启不来。
网上很多会说需要在Application.java里添加如下注解:
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
没有问题,至少能保证你在云服务器上的服务可以成功启动。但是这只是规避,没有从根本上解决问题!我的做法是,需要在resource->config->新建application.yaml文件,在此文件里添加mysql的配置。(application.propertie里的配置可保留,可删除,建议删除!)
server:
port: 8088
spring:
datasource:
name: fademo
url: jdbc:mysql://localhost:3306/test?useSSL=false&useUnicode=true&characterEncoding=utf-8&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai
username: ah
password: 666666
# 使用druid数据源
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
问题2. 报“Cannot determine embedded database driver class for database type NONE”之类的问题
如果采用“问题1”的方法,还是没能解决问题,建议重新build下项目,清楚下缓存即可。
问题3. 报“deny 'ah'@'localhost'”等问题
这个问题,需要你在云数据库上给用户ah添加权限。添加步骤如下:
步骤1. mysql -u ah -p;
->输入数据库密码
->创建用户:create user ah@'%' identified by '666666';
->grant all on *.* to ah@'%' identified by '123456';
->查询mysql数据库下的user表:select user,host,plugin from mysql.user;
->确保host字段为%,plugin字段为mysql_native_password即可。
问题4. 报“errorCode 0, state 08S01”和“The last packet sent successfully to the server was 0 milliseconds ago”问题
这个问题,说明你的云服务器上的数据库连不上,这时候你需要你你买的云的官网,在安全组里添加3306端口。