Home Database Mysql Tutorial MySQL is often misunderstood by us

MySQL is often misunderstood by us

Feb 21, 2017 am 10:38 AM
mysql



MySQL, as a major force in databases, exists everywhere in our various systems. I believe everyone is familiar with it! However, just because you know you can use it doesn't mean you know the details, so let's take stock of some of the things we usually don't pay much attention to, firstly for fun, and secondly to prevent ourselves from stepping into pitfalls.

Disclaimer: If you want to know the details, then read the source code. I really don’t have that ability, so I can only talk about some things from a one-sided perspective!

1. Case-insensitive (field name)

MySQL query field names are not case-sensitive, but the query content is case-sensitive. , so if you can use underscores to name, don’t use case distinction in naming, such as:

  1. SELECT uid, v_state FROM all_user WHERE username = 'sunyue';

  2. SELECT uid,v_state FROM all_user WHERE USERNAME = 'sunyue'; //Same result as the previous statement, fields are not case-sensitive


  3. ##SELECT uid,v_state FROM all_user WHERE USERname = 'SUNYUE'; //No information found, the content must be size-sensitive Write

Copy code

2. Fuzzy matching ([_] matches any character)

Although fuzzy matching has a bit of a regular meaning, you cannot match it in the database as freely as a regular match, so just try to simplify the matching as much as possible! (Additional noun: full-text search sphinx)

  1. SELECT uid,v_state FROM all_user WHERE USERNAME LIKE 'su_yue'; //Underscore [_] matches any single character

  2. SELECT uid,v_state FROM all_user WHERE USERNAME LIKE 'su%yue'; //% matches any number of characters

  3. SELECT uid,v_state FROM all_user WHERE USERNAME NOT LIKE 'su%'; /t likeGet the information not included

##Copy code

3. How to guess a function

As a relational database, mysql is aimed at ordinary developers, so everything should be as humane as possible. So, if you don’t know what a certain function is, then maybe you can guess it, because if a function makes it impossible for others to guess, then maybe it is a failed design. For mysql, as long as your English level is slightly better, you can easily think of how to write a relational query. Therefore, the ability to guess depends on your English level, hahaha! ! !

4. replace into syntax

replace into is a very crude insertion method, but it is also necessary to use it in appropriate scenarios. For example, some data that needs to be overwritten at any time should be replaced, but for some auto-increment tables, You should try to avoid using it, because it will be a waste of ID, and there may be no need to use replace.

5. insert into on dumplicate key update syntax

This writing method is relatively gentle, but the speed is definitely slower. It is said that only mysql has this feature. If you don’t want to check whether the data already exists before inserting, maybe this is a good choice!

6. explain syntax

This is an effective way to check the query effect. In fact, I rarely use this function, but if a developer often uses this Function, then, I believe that he must be an awesome person. Through this command, you can determine whether the statement you wrote is optimized, and if not, what is the direction. It should be said that the more you use it, the more you will know the results, so just use it more!

7. Index length

The maximum index length of myisam is 1000 bytes, and the maximum index length of innodb is 767 bytes! Be careful when using it. If it exceeds the range, it will exceed expectations!

8. Copying the library

1) Directly data the database backup and recovery command that comes with mysql;

2) Directly copy the file to the destination server (Pay attention to the process occupation problem);

3) Use tools for synchronization; I personally feel that the second method is the easiest!

9. Partitioning

For some tables that may be very large, partitioning operations are required. If there is a need for this, you need to add at least one at the beginning. Partition, otherwise the partition will not be able to be operated later. (At least I think so)

10. Slow query

Slow query, this is a performance monitoring problem. If the server performance is too poor, when troubleshooting, there will be records of such slow queries, and the troubleshooting will be more effective!

11. Binlog

binlog, this function is generally used. It is very necessary for data recovery, data operation recording, etc.!

12. Other views, stored procedures, events, etc. that you should know...

Views, events, etc. These are some advanced applications. I found that many projects This kind of application does not exist at all, and at least the projects I have encountered are almost never involved, or if they are, it is done casually by others! But you still need to understand the advanced functions, whether they are useful or not!

13. Available tools

phpMyAdmin, as a remote and safe way to operate the database, is still very good, but as a local operation, it is a bit clumsy; sqlyog , although the interface is old-fashioned, it is still relatively convenient; navicat is more professional, but you have to adapt to its various forms of expression; command line, I think no one will use the command line directly for operations, but the command line is It’s fundamental!

There are many things that need to be deepened. If you have the time and ability, you should delve into the source code!

The above is the content of MySQL that is often misunderstood by us. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

How to open phpmyadmin How to open phpmyadmin Apr 10, 2025 pm 10:51 PM

You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

MySQL's Place: Databases and Programming MySQL's Place: Databases and Programming Apr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

How to connect to the database of apache How to connect to the database of apache Apr 13, 2025 pm 01:03 PM

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.

How to start mysql by docker How to start mysql by docker Apr 15, 2025 pm 12:09 PM

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

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.

How to install mysql in centos7 How to install mysql in centos7 Apr 14, 2025 pm 08:30 PM

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

See all articles