- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to mask data fields in MySQL?
To mask data fields, use CONCAT() along with REPEAT(). Here, we will mask data fields with #. Let us first create a −
mysql> create table DemoTable1410 -> ( -> Password varchar(80) -> ); Query OK, 0 rows affected (0.51 sec)
Insert some records in the table using 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)
Display all records from the table using select −
mysql> select * from DemoTable1410;
This will produce the following output −
+---------------+ | Password | +---------------+ | John12345678 | | Carol_897 | | David_5647383 | +---------------+ 3 rows in set (0.00 sec)
Here is the query to mask data fields in 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
Let us check the table records once again −
mysql> select * from DemoTable1410;
This will produce the following output −
+---------------+ | Password | +---------------+ | John1####### | | Carol#### | | David######## | +---------------+ 3 rows in set (0.00 sec)
- Related Articles
- How to concatenate fields in MySQL?
- How to ORDER BY grouped fields in MySQL?
- How can we MySQL LOAD DATA INFILE statement with ‘FIELDS TERMINATED BY’ option to import data from text file into MySQL table?
- How to mask user email addresses with a different domain in MySQL?
- How to display the bit(1) fields in MySQL?
- Substring() for Fields in MySQL?
- Get or set the mask of the array if it has no named fields in Numpy
- Mask an array where the data is exactly equal to value in Numpy
- How to apply Substring() for fields in MySQL to get part of string?
- How to SELECT fields from one table and INSERT to another in MySQL?
- How to mask an image in OpenCV Python?
- Using GROUP_CONCAT() on bit fields returns garbage in MySQL? How to fix?
- Python Tkinter – How to export data from Entry Fields to a CSV file?
- MySQL find/ replace string in fields?
- How to fetch fields with multiple values set using MySQL LIKE?

Advertisements