spring boot 配置文件application中连接数据库的配置文件写是localhost能正常连接数据库,但是改为本机的ip之后启动项目报错
问题原因:mysql 没有开启远程允许远程连接的权限
1 .登录mysql
mysql -u root -p 回车
输入密码
输入密码进入mysql
2.切换到mysql 数据库,然后输入下面两条命令
grant all privileges on *.* to 'root'@'%' identified by '2222222' with grant option;
flush privileges;
注:%表示允许任何ip地址的电脑用root帐户和密码(2222222)来访问这个mysql server。
3.重启mysql服务
windows+R 弹出运行框 在运行框中输入cmd + 回车 进入系统的dos窗口
停止mysql:输入 net stop mysql;
启动mysql:输入 net start mysql;
windows下不能直接重启(restart),只能先停止,再启动。
之后就能在application中配置ip连接数据库了·