mysql脫敏測試環境實現物理脫敏

來源:互聯網
上載者:User

標籤:mysql脫敏

實現情境及需求:
因為業務需求:包含顧客隱私不被泄露,將在測試環境進行資料庫脫敏操作

python 3.6

實現方法,截取訂單後四位元字,截取顧客前7位電話號碼,實現字串拼接,將7位電話號碼和後4位訂單號進行拼接,然後直接修改資料庫

import pymysqlconn = pymysql.connect(    host=‘serverIP‘,    port=3306,    user=‘username‘,    passwd=‘password‘,    db=‘DBname‘,    charset=‘utf8‘)cursor = conn.cursor()sql_select = ‘select shop_id,phone_num from shopcar‘res = cursor.execute(sql_select)result = cursor.fetchall()for i in result :        only_id = i[0]        only_int = str(only_id)[-4:]        phone_num = i[1]        phone_int=str(phone_num)[:7]        m_sql=phone_int+only_int        min_sql=int(m_sql)        sql=‘update shopcar set phone_num="%s" where shop_id="%s"‘ % (m_sql,only_id)        cursor.execute(sql)conn.commit()cursor.close()conn.close()

結果:

mysql> select * from shopcar;+---------+-------------+--------------------+| shop_id | phone_num   | auth_num           |+---------+-------------+--------------------+| 1245780 | 15816905780 | 429322199008084023 || 1245781 | 15816905781 | 429322199008084024 || 1245782 | 15816905782 | 429322199008084022 || 1245783 | 15816905783 | 429322199008084011 |+---------+-------------+--------------------+4 rows in set (0.00 sec)mysql> 

mysql脫敏測試環境實現物理脫敏

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.