当前位置:网站首页>Common MySQL errors and solutions summarized painstakingly (II)
Common MySQL errors and solutions summarized painstakingly (II)
2022-06-29 07:49:00 【Best audience!】
MySQL Common error summary table of contents
Chapter one [MySQL Error summary ( Recommended collection )Chapter two MySQL Error summary ( Recommended collection )
MySQL Common error summary table of contents
- MySQL Common error summary table of contents
- Preface
- One 、MySQL Error summary ( Two )
- 1007 - Can't create database 'myt3'; database exists
- 1062 - Duplicate entry 'XXX for key 'XXX'
- 1091 - Can't DROP XXX; check that column/key exists
- 1115 - Unknown character set: 'utf-8'
- 1136 - Column count doesn't match value count at row 1
- 1138 - Invalid use of NULL value
- 1166 - Incorrect column name 'owner '
- Wrong number 1251 Client does not support authentication protocol requested by server;consider upgrading MysQL client
- 1264 - Out of range value for column 'f1' at row 1
- 1406 - Data too long for column 'c_gender' at row 1
- 1423 - Field of view 'XXX' underlying table doesn't have a default value
- 1439 - Display width out of range for column 'XX' (max = 64)
- 1452 - Cannot add or update a child row: a foreign key constraint fails (`test01_office`.`emp`, CONSTRAINT `emp_ibfk_1` FOREIGN KEY (`deptid`) REFERENCES `dept1` (`did`))
- 1822 - Failed to add the foreign key constraint. Missing index for constraint 'XXX' in the referenced table 'XXX'
- 3780 - Referencing column 'deptid' and referenced column 'did' in foreign key constraint 'emp_ibfk_1' are incompatible.
Preface
️ When operating the database , There are always some common mistakes , These errors look different , But everything is the same ,So I have the idea to sum up these common mistakes , I hope it can help readers who read this article , In this way, this article also has meaning .
If you feel helpful, you can ** Like collection ** support , It would be great if you could pay attention ️
One 、MySQL Error summary ( Two )
1007 - Can’t create database ‘myt3’; database exists
Problem analysis and solutions
- 1 . This is because the current table already exists , Re creation will repeat ,
The following statement is recommended to create
CREATE DATABASE IF NOT EXISTS myt3 CHARACTER SET 'utf-8';
1062 - Duplicate entry 'XXX for key ‘XXX’
Problem analysis and solutions
- 1 . Field sets a unique constraint , When inserting data , Data re conflict
1091 - Can’t DROP XXX; check that column/key exists
Problem analysis and solutions
- 1 . This is because when you re create a constraint , An index will be generated automatically ( If you do not specify a name when creating a unique constraint , If it's a single column , The default is the same as the column name ; If it's a composite column , Then default and () The first column in the list has the same name . You can also customize the uniqueness constraint name ), When we delete constraints , Must be the same as the constraint name to delete
- for example First, query the constraints , And the index name
SELECT * FROM information_schema.table_constraints WHERE table_name = ‘ Table name l’;
Then delete the constraint
ALTER TABLE test_notnull DROP INDEX test_unique_phone2;
1115 - Unknown character set: ‘utf-8’
Problem analysis and solutions
- 1 . This is because the character set is set incorrectly , For example, it is written as utf-8, The right one is utf8
Write it correctly
CREATE DATABASE IF NOT EXISTS myt3 CHARACTER SET 'utf8';
1136 - Column count doesn’t match value count at row 1
Problem analysis and solutions
- 1 . In the process of inserting data , Data and fields do not match ( There may be more data and fewer fields , Or less data , Many fields )
1138 - Invalid use of NULL value
Problem analysis and solutions
- 1 . The reason for this problem is , There are... In the field first NULL , The constraint of the field to be modified is NULL, The constraint fails

1166 - Incorrect column name 'owner ’
Problem analysis and solutions
- 1 . The reason is that there are spaces in the fields , Check carefully for deleted spaces
Wrong number 1251 Client does not support authentication protocol requested by server;consider upgrading MysQL client
Problem analysis and solutions
- 1 . Because mysql8 In previous versions, the encryption rule was mysql_native_password, And in the mysql8 after , The encryption rule is caching_sha2_password,
- We need to change it
> ## 1418 - This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)
Problem analysis and solutions
- 1 . This is because... Is turned on by default bin-log( Ensure that the main memory data is consistent ), You need to select... When creating the function , Indicates that the program uses SQL Sentence restrictions .

for example
1264 - Out of range value for column ‘f1’ at row 1
Problem analysis and solutions
- 1 . When inserting data , The data exceeds the value range of the data type , example 128 More than the TINYINT Of (-127——128) The scope of the , This type of error will be reported .
- The following is a common value range

1406 - Data too long for column ‘c_gender’ at row 1
Problem analysis and solutions
- 1 . When adding data , Out of range of field , Data can be modified , Or change the length of the field .
1423 - Field of view ‘XXX’ underlying table doesn’t have a default value
Problem analysis and solutions
- 1 . This happens when you add or modify view data , First, make it clear that modifying the view will also modify the contents of the data table , Then because when you start creating views , Only some data table fields are selected as views , There are constraints in other fields , For example, it can't be NULL, The transaction cannot be committed .
give an example
1 Data table salary Set not to NULL
2 Create view CREATE VIEW v_emp AS SELECT emp_id,emp_name,dept_id FROM emp2; There is no choice at this time salary Field
3 Insert view operation , Cause errors
1439 - Display width out of range for column ‘XX’ (max = 64)
Problem analysis and solutions
- 1 . This is because when a table is created or modified , The length range of the data type exceeds ,
- For example BIT The length range of the type is 1 <= M <= 64 If exceeded 64 There's a problem .
1452 - Cannot add or update a child row: a foreign key constraint fails (
test01_office.emp, CONSTRAINTemp_ibfk_1FOREIGN KEY (deptid) REFERENCESdept1(did))
Problem analysis and solutions
- 1 as a result of The referenced fields in the main table There is no such data or the value does not match , So when you add data from a table's foreign key , You can't add it in
- ( For example, the Department field in the employee table , If there is no... In the Department list 10 Department No , The employee table cannot be added to 10 Department No )
1822 - Failed to add the foreign key constraint. Missing index for constraint ‘XXX’ in the referenced table ‘XXX’
Problem analysis and solutions
- 1 . Failed to add foreign key , The reason is that the fields in the main table need The primary key of the primary table or Columns with unique constraints , Can be used as the referenced field
3780 - Referencing column ‘deptid’ and referenced column ‘did’ in foreign key constraint ‘emp_ibfk_1’ are incompatible.
Problem analysis and solutions
- 1 . The reason is from the... Of the table deptid Field and main table did word The data type of the segment is inconsistent , And they should have the same logical meaning
##4028 - A table must have at least one visible column.
Problem analysis and solutions
- 1 . This is because when creating tables , No fields are set , At least one field must be set to create a table
Wrong cases
CREATE TABLE IF NOT EXISTS myt4;
I hope it will be helpful to your study , I also hope you can give me more support , Leave your love and praise !
Finally, the best listener wishes everyone can get their favorite Offer
边栏推荐
- from xx import*等价于from xx import *,不一定要加空格
- [industrial control old horse] detailed design of PLC six way responder system
- 719. find the distance of the number pair with the smallest K (two points)
- ShapeShifter: Robust Physical Adversarial Attack on Faster R-CNN Object Detector
- Little white battle pointer (Part 1)
- 精选西门子PLC工程实例源码【共300套】
- 719. 找出第 K 小的数对距离(二分)
- 关于KingbaseES临时文件过大问题
- 蓝桥杯——13届第二批试题解析
- Schnuka: 3D visual inspection scheme 3D visual inspection application industry
猜你喜欢
随机推荐
358. K distance interval rearrange string sorting
游标长时间open导致表无法vacuum问题
Interviewer: why does database connection consume resources? Where are the resources consumed?
关于开发web场景下如何解决手机访问web跨域问题
matlab 多普勒效应产生振动信号和处理
Fluent imitates uiswitch
Software testing
Oracle batch insert data - insert ethnic data
Vulnhub's DC8 target
About the problem that the kingbasees temporary file is too large
Little white battle pointer (Part 1)
SQL 注入绕过(六)
多态中的向上和向下转型
Blue Bridge Cup - minimum frame
施努卡:什么是视觉定位系统 视觉定位系统的工作原理
Appium自动化测试基础 — ADB常用命令(二)
tf.compat.v1.global_variables
Appium自动化测试基础 — ADB常用命令(三)
软件测试鸾音鹤信
tf. compat. v1.global_ variables








