以下的文章主要介绍的是如何用MySQL内置函数来转换ip地址与相关数字,在实际操作中在处理字符格式的时候,例如将54789转换为5,4789这样的,我们只要用:format(12345,0)即可,以下就是具体内容介绍。 用MySQL内置函数转换ip地址和数字 利用两个内置函数 inet_at
以下的文章主要介绍的是如何用MySQL内置函数来转换ip地址与相关数字,在实际操作中在处理字符格式的时候,例如将54789转换为5,4789这样的,我们只要用:format(12345,0)即可,以下就是具体内容介绍。
用MySQL内置函数转换ip地址和数字
利用两个内置函数
inet_aton:将ip地址转换成数字型
inet_ntoa:将数字型转换成ip地址
充分利用mysql内置的format函数
尤其是在处理字符格式的时候,例如将12345转换成12,345这样的,只要用:format(12345,0)即可,如果用format(12345,2)则显示的是12,345.00了...
利用MySQL内置函数处理时间戳问题
<ol class="dp-xml"><li class="alt"><span><span>eg : select FROM_UnixTIME(UNIX_TIMESTAMP(),'%Y %D %M %h:%i:%s %x'); </span></span></li></ol>
结果: 2004 3rd August 03:35:48 2004
利用mysql_convert_table_format转换表类型
需要DBI和DBD的mysql相关模块支持才能用,例子:
<ol class="dp-xml"><li class="alt"><span><span>mysql_convert_table_format </span><span class="attribute">--user</span><span>=</span><span class="attribute-value">root</span><span> </span><span class="attribute">--password</span><span>=</span><span class="attribute-value">'xx'</span><span> </span><span class="attribute">--type</span><span>=</span><span class="attribute-value">myisam</span><span> test yejr </span></span></li></ol>
修改mysql表中的字段名
<ol class="dp-xml"><li class="alt"><span><span>alter table tb_name change old_col new_col definition... </span></span></li></ol>
利用临时变量
<ol class="dp-xml"><li class="alt"><span><span>select @</span><span class="attribute">var1:</span><span>=</span><span class="attribute-value">a1</span><span>+a2 as a_sum,@</span><span class="attribute">var2:</span><span>=</span><span class="attribute-value">b1</span><span>+b2 as b_sum,@var1+@var2 as total_sum from test_table xxx; </span></span></li></ol>
用int类型存储ip地址
原先错误的认为必须用bigint才够,后来发现使用int unsigned类型就足够了。 :)
利用IF函数快速修改ENUM字段值
一个例子:
<ol class="dp-xml"><li class="alt"><span><span>update rule set </span><span class="attribute">enable</span><span> = </span><span class="attribute-value">if</span><span>('0' = enable,'1','0') where xxx; </span></span></li></ol>
enable 类型:enum('0','1') not null default '0'
事务无法嵌套
避免长时间的sleep连接造成的连接数超出问题
设定全局变量 wait_timeout 和 interactive_timeout 为比较小的值,例如
10(s),就能使每个sleep连接在10s之后如果还没有查询的话自动断开。
设定mysql内置函数客户端的提示符(prompt)
<ol class="dp-xml"><li class="alt"><span><span>export </span><span class="attribute">MYSQL_PS1</span><span>=</span><span class="attribute-value">"(\u:\h:)\d> "</span><span> </span></span></li></ol>
则用 mysql -hlocalhost -uroot -pxx db_name 登录后,提示符变成:
<ol class="dp-xml"><li class="alt"><span><span>(root:localhost:)db_name</span><span class="tag">></span><span> </span></span></li></ol>
好用吧 :), 时时刻刻提醒你在哪个服务器上,尽量避免误操作的发生
更详细的请查看MySQL手册
整理MyISAM碎片
1.) 定期运行 OPTIMIZE TABLE 命令即可
2.) 用mysqldump出数据,然后重新import回去,这对大表来说显然第一种方法比较方便
整理Innodb碎片
1.) 运行NULL命令, ALTER TABLE XXX ENGINE=Innodb;
2.) 同上的mysqldump方法
MySQL如果认为检索的记录数量超过总记录数的30%,则选择全表扫描,而非使用索引
MySQL 5.0.3之后,VARCHAR字段后面的空格就不再删除
升级到4.1.1或更高后,就很难降级回到4.0或4.1了,因为 InnoDB 使用了多个表空间的缘故
MySQL 4.1之后,MySQL把字符串类型字段的长度定义理解为字符长度而不是字节长度
MySQL 4.1=>5.0时,增加了一个新的启动选项 innodb_table_locks,它导致 LOCK TABLE 时也可以请求 InnoDB
表锁。这个选项默认打开,不过可能在 AUTOCOMMIT=1 和 LOCK TABLES 应用中会导致死锁
5.0.3开始,在计算 DECIMAL 值和舍入精确值的时候采用精确数学,DECIMAL 用更有效的格式来存储
从5.0.12开始,自然连接和使用 USING
的连接,包括外部连接的衍生形式,都按照SQL:2003标准来处理了;这个变化导致减少了自然连接和使用 USING
的连接产生的结果字段数,并且还将按照更合理的顺序显示这些字段,逗号比较符的优先顺序和 JOIN, LEFT JOIN 中的一样了
在以前,等待超时的锁会导致 InnoDB 回滚当前全部事务,从5.0.13开始,就只回滚最近的SQL语句了
InnoDB 和 MyISAM 表中空格结尾的 TEXT 字段索引顺序改变了。因此需要运行 "CHECK TABLE" 语句修复数据表,如果出现错误,就运行
"OPTIMIZE TABLE" 或 "REPAIR TABLE" 语句修复,甚至重新转储(用mysqldump)
MySQL 5.0.3到5.0.5之间版本的 MyISAM 和 InnoDB 表中创建的 DECIMAL 字段升级到5.0.6之后会发生崩溃。
以上的相关内容就是对用MySQL内置函数转换ip地址和数字的介绍,望你能有所收获。

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Atom editor mac version download
The most popular open source editor

Zend Studio 13.0.1
Powerful PHP integrated development environment