续接上文springboot,在创建用户及数据库后,咱们开始编写远程连接数据库项目,在实现远程连接数据库之前,需要对几个方面进行认证:
1、为了使远程连接数据安全,创建了一个名为【xiaochun】的用户,并赋予了对【spring】数据库的操作权限;思考:为什么不使用【root】用户连接呢?之后如何对用户管理?
2、Spring Boot是什么?Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。
一、创建远程登陆用户
select * from information_schema.user_privileges;
显示所有用户;
drop user 'xiaochun'@'localhost';
删除名为 【xiaochun】的用户;
flush privileges;
生效;
create user 'xiaochun'@'%' identified by '密码';
//'%':创建用户,并赋予远程登陆
flush privileges;
生效;
grant all privileges on spring.* to 'xiaochun'@'%';
给予用户【xiaochun】对数据库【spring】的所有操作权限;
生效;
flush privileges;
生效;
exit;
退出
二、远程连接
阿里云连接mysql详细参考:https://www.cnblogs.com/Lcch/p/16620359.html
使用【mysql workbench】登陆,如下:
验证是否拥有对 spring 数据库的权限;
本节完成,下一章节介绍,如何在代码中实现。
思考:grant all privileges on *.* to 'xiaochun'@'%';
为何不可以这样编写?