Importing and exporting binary data with Hex and Unhex functions in MySQL

Source: Internet
Author: User

Read the data and spell the SQL statement, and then import. The specific methods are:

(1) When exporting, the hex function is used to read the data, and the binary data is converted into a 16 binary string;

Select HEX (Binfield) from TestTable;

(2) When importing, the Unhex function is used to convert the 16 binary string into the binary data import library;

INSERT INTO TestTable Binfield values (Unhex (@hexstr));

The following code can demonstrate the functionality of hex and Unhex:

SELECT HEX (' This is a test str '), the result of the query is: 746869732069732061207465737420737472
SELECT unhex (' 746869732069732061207465737420737472 '), the result of the query is: The is a test str

You can also directly read 16-character characters, preceded by a string with 0x preamble:
SELECT 0x746869732069732061207465737420737472, query result: This is a test str

Importing and exporting binary data with Hex and Unhex functions in MySQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.