如何在 MySQL 中掩码数据字段?
如需掩码数据字段,请使用 CONCAT() 和 REPEAT()。此处,我们将使用 # 掩码数据字段。我们首先创建一个 −
mysql> create table DemoTable1410 -> ( -> Password varchar(80) -> ); Query OK, 0 rows affected (0.51 sec)
使用 insert 向表中插入一些记录 −
mysql> insert into DemoTable1410 values('John12345678');
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable1410 values('Carol_897');
Query OK, 1 row affected (0.20 sec)
mysql> insert into DemoTable1410 values('David_5647383');
Query OK, 1 row affected (0.17 sec)使用 select 显示表中的所有记录 −
mysql> select * from DemoTable1410;
这将产生以下输出 −
+---------------+ | Password | +---------------+ | John12345678 | | Carol_897 | | David_5647383 | +---------------+ 3 rows in set (0.00 sec)
以下是对 MySQL 中的数据字段进行掩码的查询 −
mysql> update DemoTable1410
-> set Password=concat(substr(Password, 1, 5), repeat('#', char_length(Password) - 5));
Query OK, 3 rows affected (0.16 sec)
Rows matched: 3 Changed: 3 Warnings: 0让我们再次检查表记录 −
mysql> select * from DemoTable1410;
这将产生以下输出 −
+---------------+ | Password | +---------------+ | John1####### | | Carol#### | | David######## | +---------------+ 3 rows in set (0.00 sec)
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP