Use MySQL built-in functions to convert IP addresses and numbers

Source: Internet
Author: User
Tags mysql functions
How to use MySQL functions to convert IP addresses and numbers

Use MySQL built-in functions to convert IP addresses and numbers

Using two built-in functions

Inet_aton: converts an IP address to a number.

Inet_ntoa: convert a numeric type to an IP address

Make full use of the MySQL built-in format Function

Especially when processing character formats, for example, to convert 12345 to 12,345, you only need to use: Format (12345, 0). If format (12345, 2) is used, 12,345.00 is displayed...

Use MySQL built-in functions to handle timestamp Problems

Eg: Select from_unixtime (unix_timestamp (), '% Y % d % m % H: % I: % S % x ');

Results: 2004 3rd August 03:35:48 2004

Use mysql_convert_table_format to convert the table Type

DBI and DBD mysql-related modules are required for use. Example:

Mysql_convert_table_format-user = root-Password = 'xx'-type = MyISAM test yejr

Modify the field name in the MySQL table

Alter table tb_name change old_col new_col definition...

Use temporary variables

Select @ var1: = A1 + A2 as a_sum, @ var2: = b1 + B2 as B _sum, @ var1 + @ var2 as total_sum from test_table xxx;

Store IP addresses of the int type

The original error was deemed to be sufficient only when the bigint type was used. later it was found that the int unsigned type was sufficient.

Use the IF function to quickly modify the enum Field Value

Example:

Update Rule Set enable = If ('0' = Enable, '1', '0') Where xxx;

Enable type: Enum ('0', '1') not null default '0 ′

Transactions cannot be nested

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.