Using MySQL Enterprise Data Masking and De-Identification Suppose that a  customer  table containing customer records has these columns: • id : Customer ID number. • first_name : Customer first name. • last_name : Customer last name. • ssn : Customer Social Security number. For example, the table might be defined as follows: CREATE TABLE customer ( id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY, first_name VARCHAR(40), last_name VARCHAR(40), ssn VARCHAR(11) ); The application used by customer-service representatives to check the customer SSN might execute a query like this: mysql>  SELECT id, ssn mysql>  FROM customer mysql>  WHERE first_name = ’Joanna’ AND last_name = ’Bond’; +-----+-------------+ | id | ssn | +-----+-------------+ | 786 | 906-39-0007 | +-----+-------------+ mysql>  SELECT id, mask_ssn(CONVERT(ssn USING binary)) AS masked_ssn mysql>  FROM customer mysql>  WHERE first_name = ’Joanna’ AND last_name = ’Bond’; +-----+-------------+ | id | masked_ssn | +-----+-------------+ | 786 | XXX-XX-0007 | +-----+-------------+ However, that exposes the SSN to the customer-service representative, who has no need to see anything but the last four digits. Instead, the application can use this query to display only the masked SSN: Now the representative sees only what is necessary, and customer privacy is preserved. Why was the  CONVERT()  function used for the argument to  mask_ssn() ? Because  mask_ssn() requires an argument of length 11. Thus, even though  ssn  is defined as  VARCHAR(11) , if the  ssn column has a multibyte character set, it may appear to be longer than 11 bytes when passed to a loadable function, and an error occurs. Converting the value to a binary string ensures that the function sees an argument of length 11. A similar technique may be needed for other data masking functions when string arguments do not have a single-byte character set. Creating Views that Display Masked Data If masked data from a table is used for multiple queries, it may be convenient to define a view that produces masked data. That way, applications can select from the view without performing masking in individual queries. 1582