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)
阅读更多:MySQL 教程
极客教程