MySQL使用tips_MySQL
用mysql内置函数转换ip地址和数字
利用两个内置函数
inet_aton:将ip地址转换成数字型
inet_ntoa:将数字型转换成ip地址
充分利用mysql内置的format函数
尤其是在处理字符格式的时候,例如将12345转换成12,345这样的,只要用:format(12345,0)即可,如果用format(12345,2)则显示的是12,345.00了...
利用mysql的内置函数处理时间戳问题
eg : select FROM_UNIXTIME(UNIX_TIMESTAMP(),'%Y %D %M %h:%i:%s %x');
结果: 2004 3rd August 03:35:48 2004
利用mysql_convert_table_format转换表类型
需要DBI和DBD的mysql相关模块支持才能用,例子:
mysql_convert_table_format --user=root --password='xx' --type=myisam test yejr
修改mysql表中的字段名
alter table tb_name change old_col new_col definition...
利用临时变量
select @var1:=a1+a2 as a_sum,@var2:=b1+b2 as b_sum,@var1+@var2 as total_sum from test_table xxx;
用int类型存储ip地址
原先错误的认为必须用bigint才够,后来发现使用int unsigned类型就足够了。 :)
利用IF函数快速修改ENUM字段值
一个例子:
update rule set enable = if('0' = enable,'1','0') where xxx;
enable 类型:enum('0','1') not null default '0'
事务无法嵌套
避免长时间的sleep连接造成的连接数超出问题
设定全局变量 wait_timeout 和 interactive_timeout 为比较小的值,例如
10(s),就能使每个sleep连接在10s之后如果还没有查询的话自动断开。
设定mysql客户端的提示符(prompt)
export MYSQL_PS1="(u:h:)d> "
则用 mysql -hlocalhost -uroot -pxx db_name 登录后,提示符变成:
(root:localhost:)db_name>
好用吧 :), 时时刻刻提醒你在哪个服务器上,尽量避免误操作的发生
更详细的请查看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之后会发生崩溃

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

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.

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

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

When developing an e-commerce website using Thelia, I encountered a tricky problem: MySQL mode is not set properly, causing some features to not function properly. After some exploration, I found a module called TheliaMySQLModesChecker, which is able to automatically fix the MySQL pattern required by Thelia, completely solving my troubles.
