spring boot使用mybatis連接MySQL:
applicationg.yml設置:
spring:
datasource:
url: jdbc:mysql://***.*.***.***:3306/socks?useSSL=false
username: root
password: *******
driver-class-name: com.mysql.cj.jdbc.Driver
mybatis:
configuration:
map-underscore-to-camel-case: true #開啟駝峰映射
啟動類中添加@MapperScan(),解決啟動時找不到bean的問題
@MapperScan("com.***.***.mapper")
華為雲綁定公網IP后連接超時的問題:
在華為雲安全組-添加入向規則,增加3306端口,允許所有IP訪問
連接后提示無權限訪問:
Access denied for user 'root'@'***.***.***.***' (using password: YES)
在Mysql數據庫中執行以下語句放開root用戶的外網訪問權限
grant all privileges on *.* to root@'%' identified by '******' //***表示數據庫連接密碼