本地打包的springboot项目,用主从分库,nginx在192.168.40.128上,项目部署在192.168.40.129上,在两个虚拟机分别建立mysql数据库,192.168.40.128是主库,192.168.40.129是从库。
在windows本地可以连接到这两个服务器,并且功能测试OK,但是项目打包到linux下,在用的nginx反向代理到接口,能正常发送到,但日志报错
java.sql.SQLException: Access denied for user 'root'@'127.0.0.1' (using password: YES)
这是yml文件数据库部分。
shardingsphere:
datasource:
names:
master,slave
master:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.40.128:3306/reggie?characterEncoding=utf-8&useSSL=false
username: root
password: root
slave:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.40.129:3306/reggie?characterEncoding=utf-8&useSSL=false
username: root
password: root
masterslave:
# 读写分离配置
load-balance-algorithm-type: round_robin #轮询
# 最终的数据源名称
name: dataSource
# 主库数据源名称
master-data-source-name: master
# 从库数据源名称列表,多个逗号分隔
slave-data-source-names: slave
props:
sql:
show: true #开启SQL显示,默认false
main:
allow-bean-definition-overriding: true
java.sql.SQLException: Access denied for user 'root'@'127.0.0.1' (using password: YES)
主要在windows能正常运行,连接的也是虚拟机的mysql数据库,128主库和129从库,一切正常,
但部署到linux就报错。应该不是账号密码空格等问题,可能权限之类的问题,但本地能连接,按道理linux上也可以连接。
有没有可能是部署在192.168.40.129的问题。搞不太懂。
我新开一台虚拟机试试。
希望能正常跑
你的MySQL数据库,没有开启远程访问权限
use mysql #访问mysql库
update user set host = '%' where user = 'root'; #使root能再任何host访问
FLUSH PRIVILEGES; #刷新