MySQL 5.7 新增默认账号 mysql.session和mysql.sys

MySQL 5.7 新增默认账号 mysql.session和mysql.sys,第1张

在闲逛mysql时发现mysql库的user表下有两个账户比较特别:mysql.session 和 mysql.sys查一下 user 表里面都有哪些账户:mysql.sys@localhost:用于 sys schema 中对象的定义。使用 mysql.sys 用户可避免 DBA 重命名或者删除 root 用户时发生的问题。该用户已被锁定,客户端无法连接。mysql.session@localhost:插件内部使用来访问服务器。该用户已被锁定,客户端无法连接。 root@localhost:这个就是 root 账号啦!其用于管理。该用户拥有所有权限,可执行任何 *** 作。严格来说,这个账号不应该被保留。 root 是 MySQ L的特权账号,这个众所周知,也带来安全隐患。建议将root账号禁用或者删除,新建一个特权账号用于管理。 在MySQL 5.6以前,我们通过 show processlist\G 命令查看系统中正在运行的所有进程: 从5.7开始,我们又可以通过 sys.session 表来查看系统正在运行的所有进程,而且该表中的记录相 processlist 比较完善: 很显然, select * from sys.session 能得到更多的信息。

由于项目需要,需要为我的springMCV项目配置mysql+oracle两种数据源,运行时进行切换。由于技术水平有限,断断续续用了一周时间解决了这个小问题(比较懒),特来发篇博客,为以后需要的朋友提供参考。

首先,这个项目的多数据源配置建立在mysql已经搭建完成的基础上,这部分的源代码github上都有,网上也有不少教程,我就不作说明了,直接讲如何配置oracle。

oracle我用的版本是11g,具体版本是11.2.0.1.0。下载及安装,建表过程省略(详情请百度,建表推荐用pl/sql)

我的项目中,数据库的账号密码都是通过properties文件配置的,首先你需要配置好spring项目中的oracle的url,账号以及密码。

dataSource2.driver=oracle.jdbc.driver.OracleDriver

dataSource2.url=jdbc\:oracle\:thin\:@localhost\:1521\:orcl

dataSource2.username=sys as sysdba

dataSource2.password=a123456

driver表示驱动名,username表示登录oracle的用户名,这里需要注意的是oracle非常注重数据库管理员的权限,因此在登录时需要指明登录者的身份,pl/sql以及navicat会让你选择以什么角色登录,而在spring项目中访问时,直接输入 用户名 + as sysdba 的形式作为用户名,密码就是先前安装oracle时设置的密码。

接下来配置spring的配置文件,来配置2个数据源,我主要是参考了网上的文章,大致原理是为不同数据源配置不同的sqlSessionFactory以及sqlSessionTemplate,为项目编写工具类,通过设置不同的键值切换数据源。

MySQL 5.7 新增默认账号 mysql.session和mysql.syshttps://www.jianshu.com/p/427cac0d8763Privileges Supported by MySQLhttps://dev.mysql.com/doc/refman/5.7/en/grant.htmlMySQL 5.7 Reference Manual/Reserved Accountshttps://dev.mysql.com/doc/refman/5.7/en/reserved-users.htmlWhat are mysql.session@localhost and mysql.sys@localhost user accounts good for?https://stackoverflow.com/questions/46149220/what-are-mysql-sessionlocalhost-and-mysql-syslocalhost-user-accounts-good-forOne part of the MySQL installation process is data directory initialization (see  Section 2.10.1, “Initializing the Data Directory” ).  During data directory initialization, MySQL creates user accounts that should be considered reserved:'root'@'localhost : Used for administrative purposes. This account has all privileges and can perform any operation. Strictly speaking, this account name is not reserved, in the sense that some installations rename the root account to something else to avoid exposing a highly privileged account with a well-known name.'mysql.sys'@'localhost' : Used as the DEFINER for  sys  schema objects. Use of the mysql.sys account avoids problems that occur if a DBA renames or removes the root account. This account is locked so that it cannot be used for client connections.'mysql.session'@'localhost' : Used internally by plugins to access the server. This account is locked so that it cannot be used for client connections.用于sys schema中对象的定义。使用mysql.sys用户可避免DBA重命名或者删除root用户时发生的问题。该用户已被锁定,客户端无法连接。插件内部使用来访问服务器。该用户已被锁定,客户端无法连接。root账号,其用于管理。该用户拥有所有权限,可执行任何 *** 作。 root是MySQL的特权账号,这个众所周知,也带来安全隐患,建议将root账号禁用或者删除,新建一个特权账号用于管理。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/8665297.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-19
下一篇2023-04-19

发表评论

登录后才能评论

评论列表(0条)

    保存