MySQL数据库中鲜为人知的技巧_MySQL
mysql/>MySQL易学易用,且附带丰富的技术文档,这二个因素使之被广泛应用。然而,随着mysql/>MySQL发展之迅速,即使一个mysql/>MySQL老手有时也会为该软件出其不意的功能感叹。本文将为你介绍这些不为人知的特性。 nf/eqhh-
pWshCV
以XML格式查看查询结果 !)ava \
~r]XFU
通过使用传统—xml 选项调用MySQL命令行客户程序,你可以以XML格式(而不是传统的列表形式)来查看MySQL查询结果。如果你打算将查询输出与其它程序集成在一起,这一技巧非常有用,这里是一个例子: $t_pCEw\ e
+LZ| hqI
表A |$;jP
SQlEb)tr
shell> mysql --xml VSW~YP9
@.JD_m N
mysql> SELECT * FROM test.stories; sdYD/Y
>XUTBJX4
!/vK Y
EPG[e7
\nSVw!$k
1 wIl}
This is a test gr']aUi09
2005-07-28 00:14:57 7DBWyUV
S~Eqn 0\!
!Z8Kb3MxGF
S= ev" yN
2 mZsdvBv:'
This is the second test "vAnQf
2005-07-28 00:15:11 iO[sQP]
{TNT.
t @-DS.ZR
2 rows in set (0.11 sec) !8cN8tb
2dQ! y
快速重建索引 T~5wULw'
lt.BWF
通常情况下,如果你想改变服务器的全文搜索变量,你需要在表格中重新建立全文索引,以确保你的更新得到映射。这一操作将会花费大量的时间,特别是如果你需要处理很多数据的时候。一种快速的解决方法是使用REPAIR TABLE命令,以下为演示过程: 1#\ X]-
p:JI $L;)
表B $ l{ N8LD
Q r
mysql> REPAIR TABLE content QUICK; &\UYYJxyz
+-----------+--------+----------+----------+ H Lit@g
| Table| Op| Msg_type | Msg_text | Ki}1To
+-----------+--------+----------+----------+ dK~ 1@
| content| repair | status| OK| -Wv c$SX
+-----------+--------+----------+----------+ $CUCXz[>n
1 row in set (0.05 sec) D~!au:\$
c%uz6 l
压缩一定的表格类型 L5NGMF{zNL
_ }]\ i-
如果你处理的是只读MyISAM表格,MySQL允许你将其压缩以节省磁盘空间。对此可以使用包括myisampack,如下所示: @=R dG
%[z.zY2=
表C d*-2+ D 5&
ikK\9gB)(
shell> myisampackmovies.MYI k"* \s .C
Compressing movies.MYD: (146 records) )Xblx
- Calculating statistics vP5R"4?
- Compressing file caa 3MA>
41.05% - ?0qz[4
t({t:|h
使用传统SQL a,G{OtBB
$_F j
MySQL支持SQL查询中的传统用法,支持IF与CASE结构。以下是一个简单的例子: @b`@7L}Z
\J-Tw^E
表D O8T2(P$Rc
JRm&Oc9v
mysql> SELECT IF (priv=1, 'admin', 'guest') As usertype FROM privs WHERE username = 'joe'; #N3blF%v
+----------+ e&Nm%#9Z;
| usertype | u[kdlZnqyc
+----------+ Bk!]Tw s|1
| admin| YIUj7H
+----------+ Cvd^|^&3+!
1 row in set (0.00 sec) 8nmS;o
hNBHeK
以CSV格式输出表格数据 uf@!CLF
4`K
MySQL输出文件包含一个全部SQL命令列表。如果你想将输出文件导入到MySQL,这一功能非常实用,但如果目标程序(比如Excel)不能与SQL相互通讯,这一方法将行不通。在这种情况下,可以通过告诉MySQL以CSV格式建立输出文件,这种CSV格式很方便地导入到绝大部分的程序。这里演示了mysqldump的操作过程: MTiNuo`M
{6VgfC\
shell> mysqldump -T . --fields-terminated-by=", " mydbmytable UD@6D>Q~"u
L{,7Wb+[%)
这将在当前目录中生成一个文本文件,包含来自mydb.mytable列表中以逗号为间隔符的记录。 b@oLlb4-w
cHg5 ]dK-
以激活strict模式减少“bad”数据的出现 DA5WPDj-
a]BbGS
MySQL服务器能够以多种不同的模式运行,而每一种都针对于特定的目的而优化。在默认情况下,没有设置模式。然而,通过在服务器命令行中添加以下选项可以很容易地改变模式的设置并将MySQL以“strict”模式运行: 5mM#W:r
@ZP%T_(
shell> mysqld --sql_mode="STRICT_ALL_TABLES" & !

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











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.

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

In MySQL, the function of foreign keys is to establish the relationship between tables and ensure the consistency and integrity of the data. Foreign keys maintain the effectiveness of data through reference integrity checks and cascading operations. Pay attention to performance optimization and avoid common errors when using them.

The main difference between MySQL and MariaDB is performance, functionality and license: 1. MySQL is developed by Oracle, and MariaDB is its fork. 2. MariaDB may perform better in high load environments. 3.MariaDB provides more storage engines and functions. 4.MySQL adopts a dual license, and MariaDB is completely open source. The existing infrastructure, performance requirements, functional requirements and license costs should be taken into account when choosing.

SQL is a standard language for managing relational databases, while MySQL is a database management system that uses SQL. SQL defines ways to interact with a database, including CRUD operations, while MySQL implements the SQL standard and provides additional features such as stored procedures and triggers.

Safely handle functions and regular expressions in JSON In front-end development, JavaScript is often required...

Redis is a memory data structure storage system, mainly used as a database, cache and message broker. Its core features include single-threaded model, I/O multiplexing, persistence mechanism, replication and clustering functions. Redis is commonly used in practical applications for caching, session storage, and message queues. It can significantly improve its performance by selecting the right data structure, using pipelines and transactions, and monitoring and tuning.
