Mysql ignores primary key conflicts and prevents repeated insertion of bitsCN.com
Several ways for mysql to ignore primary key conflicts and avoid repeated inserts
Solution 1: Use the ignore keyword
Solution 2: Use replace
Solution 3: ON DUPLICATE KEY UPDATE
Solution 1: Use the i
Solve the problem of ignoring users in MySQL. if the following error occurs, it means that an account with an invalid password is found in the user table when mysqld is started or the authorization table is reloaded.
User 'some _ user' @ 'some _ host' password error found: ignore user.
As a result, the license system simply ignores the account.
The following describes possible causes and corrective mea
Mysql ignores primary KEY conflicts and avoids repeated inserts. solution 1: Use the ignore keyword; solution 2: Use replace into; solution 3: on duplicate key update; solution 1: if the ignore keyword is used to identify the uniqueness of a record by using the primary key primary or unique index unique, to avoid repeated insertion of records, you can use:
Sharing the method of ignoring duplicate data when inserting MYSQL data bitsCN.com
When using the following two methods, the field must be set to "primary key" or "UNIQUE constraint (UNIQUE )".1: Use replace into (this method uses the replacement method, which is a bit similar to deleting and then inserting)
Replace into SyntaxREPLACE [LOW_PRIORITY | DELAYED][INTO] tbl_name [(col_name,...)]{VALUES | VALUE} ({expr | DEFAULT },...), (...),...Or:REPLAC
In the previous article, we mentioned two ways to INSERT and process duplicate key values in MySQL: replace into and insert into on duplicate key update, today, we will introduce the ignore into method for implementing MySQL insertion and processing duplicate key values.
Case one: Use the Ignore keyword
If the uniqueness of the record is distinguished by the primary key primary or unique index unique, it is possible to avoid duplicate insertion records:
The code is as follows
Copy Code
1 INSERT IGNORE into ' table_name ' (' email ', ' phone ', ' user_id ') VALUES (' test9@163.com ', ' 99999 ', ' 9999
Simple implementation of ignore foreign key constraints when MySQL deletes a table, mysql Constraints
Deleting a table is not very common. Be careful when deleting a table that has a foreign key Association. However, during the development process, it is common to find a Schema design problem and delete all the tables in the existing database to be re-created. In
, NAME CHAR(40) NOT NULL DEFAULT '', age INT NOT NULL DEFAULT 0, info CHAR(50) NULL, PRIMARY KEY (id))INSERT INTO person_oldVALUES (11,'Harry',20,'student'),(12,'Beckham',31,'police')SELECT * FROM person_old
As you can see, the record is successfully inserted, and person_old is represented in two records. Next, insert all the records in the person_oldperson_old table to the person table.
Complementary knowledge points: understanding of Operational Data Statement optimizationTypically, when accessing a table, the reader must first obtain a lock on the table, and if a write operation arrives, the writer waits for the reader to complete the operation (it cannot be interrupted after the query starts, so the reader is allowed to complete the operation). When the reader completes the operation of the table, the lock is lifted. If the writer is waiting, another read operation arrives,
When inserting data in MYSQL, duplicate data is ignored. when inserting data in the program, existing data is not inserted, and non-existing data is inserted. You can use the stored procedure or not exists to determine whether the stored procedure EXISTS. When using the following two methods, the field must be set to "primary key" or "UNIQUE constraint (UNIQUE )".
1: Use replace into (This method uses the replacement method, which is a bit similar to
Tags: table self-resolution case INIT.D make row database uppercase"Barrier Reproduction"Condition Description 01: A program is often reported in the Linux downgrade can not find the table, but I clearly built a table, testing, encountered some problems, from the Windows platform to access the virtual machine in the Web application, often reported not found the table, but clearly in the database to see the relevant data tables and data, It can also be found in Linux via the
1: The official explanation is: in a master-slave synchronization environment, REPLICATE-IGNORE-DB is used to set up libraries that do not need to be synchronized. The explanation is too simple, but there are still a lot of holes in it.Setting filter rules is not recommended on production libraries. If you want to set it, then use replicate_wild_ignore_table:mysql.%. The experiment is very simple, as followsFirst case from library: replicate-
In-depth study of mysql varchar and limit (easy to ignore), mysqlvarchar
Why is the title named? Commen sence refers to things that everyone should know, but often they will know something or know something about it, today I will summarize some commen sense type problems I encountered in mysql.
1. How many Chinese characters and numbers can be stored in varchar
When using the following two methods, the field must be set to "primary key" or "UNIQUE constraint (UNIQUE )".1: Use replace into (This method uses the replacement method, which is a bit similar to deleting and then inserting)Copy codeThe Code is as follows:
Replace into SyntaxREPLACE [LOW_PRIORITY | DELAYED][INTO] tbl_name [(col_name,...)]{VALUES | VALUE} ({expr | DEFAULT },...), (...),...Or:REPLACE [LOW_PRIORITY | DELAYED][INTO] tbl_nameSET col_name = {expr | DEFAULT },...Or:REPLACE [LOW_PRIO
By Ay shadow
This method should also be known to many people, but no one has written it and secretly told you this.The method can bypass many web firewalls, so I don't know if I can bypass them now, haha. However, the limitation of this method is that it is only applicable to MYSQL, and does not seem to be supported by other databases. Transfer subject:First, let's take a look at the official MySQL document
=1;Next the following statements are executed
A, SELECT id,time,title from Cnblogs WHERE time>=1315646940 ORDER by Time ASC LIMIT 2000,10
B, SELECT id,time,title from Cnblogs WHERE time>=1315646940 ORDER by Time ASC LIMIT 10
C, SELECT Id,time,title from Cnblogs ORDER by Time ASC LIMIT 3000,10
Execution Order A,b,c,a,b,c,c,a,a (note here that although I closed the cache, the last query was cached, which can be seen from the query Profiler, so cross-executes), using the follo
MySQL databaseDuring OperationIgnore userThe problem will cause a lot of inconvenience to the MySQL database and affect the work of the MySQL database. In the following article, I will introduce you to solve the problem of ignoring users and hope to help you.
If the following error occurs, an account with an invalid password is found in the User table when mysql
result is MySQL>Select sysdate (), Sleep (3), sysdate (); The result is As you can see, the time value of the now () function two times is the same, although sleep is 3 seconds in the middle, and the time value of the sysdate () function is 3 seconds apart from two. The Sysdate () date-time function is similar to now (), except that it is obtained at the execution start value, and sysdate () dynamically gets the value when the function executes.
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.