MySQL 8.0.23新特性 – 不可见列

在MySQL 8.0.23之前,表中所有的列都是可见的(如果您有权限的话)。现在可以指定一个不可见的列,它将对查询隐藏。如果显式引用,它可以被查到。****

创建表

CREATE TABLE `table1`(
    `id` INT AUTO_INCREMENT PRIMARY KEY,
    `name` VARCHAR(20),
    `age` INT INVISIBLE
);

也可以创建创建一个不可见列

ALTER TABLE `table1` ADD `score` INT invisible;

查看表字段

mysql> DESC `table1`;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id    | int         | NO   | PRI | NULL    | auto_increment |
| name  | varchar(20) | YES  |     | NULL    |                |
| age   | int         | YES  |     | NULL    | INVISIBLE      |
| score | int         | YES  |     | NULL    | INVISIBLE      |
+-------+-------------+------+-----+---------+----------------+

展示创建表

show create table `table1`;

CREATE TABLE `table1` (
  `id` int NOT NULL AUTO_INCREMENT,
  `name` varchar(20) DEFAULT NULL,
  `age` int DEFAULT NULL /*!80023 INVISIBLE */,
  `score` int DEFAULT NULL /*!80023 INVISIBLE */,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3

复制表

mysql> create table `table2` like `table1`;
mysql> DESC `table2`;
+-------+-------------+------+-----+---------+----------------+
| Field | Type        | Null | Key | Default | Extra          |
+-------+-------------+------+-----+---------+----------------+
| id    | int         | NO   | PRI | NULL    | auto_increment |
| name  | varchar(20) | YES  |     | NULL    |                |
| age   | int         | YES  |     | NULL    | INVISIBLE      |
| score | int         | YES  |     | NULL    | INVISIBLE      |
+-------+-------------+------+-----+---------+----------------+

不可见列基本操作

mysql> INSERT INTO `table1` VALUES (0, 'mysql', 25), (0, 'kenny', 35), (0, 'lefred', '44');
1136 - Column count doesn't match value count at row 1

mysql> INSERT INTO `table1` (id, name, age) VALUES (0, 'mysql', 25), (0, 'kenny', 35), (0, 'lefred', '44');
Query OK, 3 rows affected (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 0

查询

mysql> SELECT * FROM `default`.`table1` LIMIT 0,1000;
+----+--------+
| id | name   |
+----+--------+
|  1 | mysql  |
|  2 | kenny  |
|  3 | lefred |
+----+--------+
mysql> SELECT `id`, `name`, `age` FROM `default`.`table1` LIMIT 0,1000;
+----+--------+-----+
| id | name   | age |
+----+--------+-----+
|  1 | mysql  |  25 |
|  2 | kenny  |  35 |
|  3 | lefred |  44 |
+----+--------+-----+
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇