Mysql---安全值守常用语句

文章目录


一.用户权限设置

用户设置

#用户创建
create user "用户名"@"%主机名" identified by "密码"
#用户删除
drop user 用户名
#用户查询
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> select user,host from user;
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| root             | %         |
| mysql.infoschema | localhost |
| mysql.session    | localhost |
| mysql.sys        | localhost |
+------------------+-----------+
4 rows in set (0.00 sec)

#用户授权
grant all privileges on `数据库名`.* to '用户名'@'主机名' identified by '密码';
#取消授权
revoke all privileges on `数据库名`.* to '用户名'@'主机名'
#查看用户授权情况
show grants for 用户名@"主机名"

元数据查询

#查看服务器版本信息
select version();
#查看当前数据库名
select user()
#查看服务器状态
show status 
#查看服务器配置变量
show variables
#查看数据文件存放位置
show global variables like "%文件名%"

Union联合查询 

        UNION查询是一种用于合并多个SELECT语句结果集的操作。UNION查询语句可以将两个或多个结果集合并成一个结果集,同时去除重复的行。

  1. UNION查询的结果集中的列名由第一个SELECT语句确定。
  2. UNION查询的结果集的列数和列类型由第一个SELECT语句确定。
  3. UNION查询中的每个SELECT语句必须具有相同的列数和相同或兼容的数据类型。
  4. UNION查询会自动去除重复的行,如果想保留重复的行,可以使用UNION ALL。
  5. UNION查询默认按照第一个SELECT语句的列顺序排序,如果想要指定排序规则,可以在最后一个SELECT语句中使用ORDER BY子句。
SELECT column1, column2, ... FROM table1
UNION
SELECT column1, column2, ... FROM table2;

 分组查询

group_concat();

#将同一学号的课程号以及成绩聚合并安装成绩降序排序
select sid,group_concat(cid),group_concat(cj order by cj desc separator "") from score group by sid

 字符串函数


总结

相关推荐

  1. MySQL语句

    2024-03-31 23:52:03       43 阅读
  2. MySQL语句

    2024-03-31 23:52:03       55 阅读
  3. MySQL语句

    2024-03-31 23:52:03       23 阅读
  4. Mysql语句

    2024-03-31 23:52:03       16 阅读
  5. Mysqlsql语句

    2024-03-31 23:52:03       37 阅读
  6. mysql--sql语句

    2024-03-31 23:52:03       22 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-31 23:52:03       5 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-31 23:52:03       5 阅读
  3. 在Django里面运行非项目文件

    2024-03-31 23:52:03       4 阅读
  4. Python语言-面向对象

    2024-03-31 23:52:03       6 阅读

热门阅读

  1. 记 SpringBoot 使用@RequestBody 接收不到参数

    2024-03-31 23:52:03       22 阅读
  2. of_get_named_gpio()函数解析

    2024-03-31 23:52:03       23 阅读
  3. go | channel direction、channel sync、channelbuffer

    2024-03-31 23:52:03       25 阅读
  4. 【WPF应用19】WPF中的Button控件详解

    2024-03-31 23:52:03       26 阅读