当前位置:网站首页>MySQL - Summary of common SQL statements
MySQL - Summary of common SQL statements
2022-07-25 15:37:00 【Andya_ net】

Pay attention to WeChat public number :CodingTechWork, Learn together .
introduction
Record and sort out commonly used SQL Statement usage notes .
Create databases and tables
Create a library (CREATE DATABASE)
CREATE DATABASE database_name
In storage (USE)
USE database_name
See the table (SHOW)
SHOW TABLES;SHOW TABLES FROM database_name;
Create table (CREATE TABLE)
CREATE TABLE table_name (column1_name INT, column2_name VARCHAR(50), column3_name VARCHAR(50));
mysql> CREATE TABLE students
-> (id INT,
-> name VARCHAR(32),
-> age INT,
-> birthday DATE,
-> class_id INT(11));
Query OK, 0 rows affected (0.34 sec)
mysql> CREATE TABLE class
-> (class_id INT AUTO_INCREMENT PRIMARY KEY,
-> class_name VARCHAR(32),
-> grade_id INT,
-> class_teacher VARCHAR(32));
Query OK, 0 rows affected (0.33 sec)
Description table (DESC)
DESCRIBE table_name;
mysql> DESC students;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(32) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
| birthday | date | YES | | NULL | |
| class_id | int(11) | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
mysql> DESC class;
+---------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+-------------+------+-----+---------+----------------+
| class_id | int(11) | NO | PRI | NULL | auto_increment |
| class_name | varchar(32) | YES | | NULL | |
| grade_id | int(11) | YES | | NULL | |
| class_teacher | varchar(32) | YES | | NULL | |
+---------------+-------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
Modify the column (ALTER TABLE)
Modify the column (CHANGE COLUMN)
ALTER TABLE table_name CHANGE COLUMN old_col_name new_col_name INT AUTO_INCREMENT PRIMARY KEY
mysql> ALTER TABLE students
-> CHANGE COLUMN id id INT AUTO_INCREMENT PRIMARY KEY;
Query OK, 0 rows affected (1.10 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> DESC students;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(32) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
| birthday | date | YES | | NULL | |
| class_id | int(11) | YES | | NULL | |
+------------+--------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
Add column (ADD COLUMN)
ALTER TABLE table_name ADD COLUMN new_col1_name TEXT , ADD COLUMN new_col2_name VARCHAR(255), ... ...
mysql> ALTER TABLE students
-> ADD COLUMN student_id INT,
-> ADD COLUMN address VARCHAR(255);
Query OK, 0 rows affected (1.10 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> DESC students;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(32) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
| birthday | date | YES | | NULL | |
| class_id | int(11) | YES | | NULL | |
| student_id | int(11) | YES | | NULL | |
| address | varchar(255) | YES | | NULL | |
+------------+--------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)
Delete column
ALTER TABLE table_name DROP COLUMN col1_name, DROP COLUMN col2_name
mysql> ALTER TABLE students
-> DROP COLUMN age;
Query OK, 0 rows affected (3.73 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> DESC students;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(32) | YES | | NULL | |
| birthday | date | YES | | NULL | |
| class_id | int(11) | YES | | NULL | |
| student_id | int(11) | YES | | NULL | |
| address | varchar(255) | YES | | NULL | |
+------------+--------------+------+-----+---------+----------------+
6 rows in set (0.00 sec)
insert data (INSERT INTO)
INSERT INTO table_name (col1_name, col2_name, col4_name) VALUES (col1_value, col2_value, col4_value);
mysql> INSERT INTO students
-> (name, birthday, address, class_id, student_id)
-> VALUES('xiaoming', '1996-07-01', ' Xiangcheng District, Suzhou City, Jiangsu Province ', 3, 080301);
mysql> INSERT INTO students
-> (name, birthday, address, class_id, student_id)
-> VALUES('xiaohong', '1995-09-05', ' Maanshan City, Anhui Province ', 3, 080310);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO students
-> (id, name, birthday, address, class_id, student_id)
-> VALUES(5, ' Qin Ming ', '1996-03-03', ' Nanjing, jiangsu province ', 2, 080205);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO students
-> (id, name, birthday, address, class_id, student_id)
-> VALUES(4, ' Huang Gai ', '1996-05-21', ' Wuxi City, Jiangsu Province ', 1, 080102);
Query OK, 1 row affected (0.00 sec)
Check the last record (LAST_INSERT_ID())
SELECT LAST_INSERT_ID();, adopt LAST_INSERT_ID() Function can take the identification code of the record just entered from the table .
SELECT LAST_INSERT_ID();
+------------------+
| LAST_INSERT_ID() |
+------------------+
| 3 |
+------------------+
1 row in set (0.00 sec)
Modifying data
Modify some columns (UPDATE SET)
UPDATE table_name SET col1_name = 'new_value' WHRE col2_name = 'xxx';, If you need to modify multiple columns , Then separate the list with commas .
Change the age number of class three to 1, Teacher changed to teacher Wu
mysql> INSERT INTO class VALUES(1, ' Class one ', '1', ' Teacher wang ');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO class VALUES(2, ' Class two ', '1', ' Miss Xu ');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO class
-> (class_id, class_name, grade_id, class_teacher)
-> VALUES (3, ' Class three ', 3, ' Mr. Chen ');
Query OK, 1 row affected (0.01 sec)
mysql> SELECT * FROM class;
+----------+------------+----------+---------------+
| class_id | class_name | grade_id | class_teacher |
+----------+------------+----------+---------------+
| 1 | Class one | 1 | Teacher wang |
| 2 | Class two | 1 | Miss Xu |
| 3 | Class three | 3 | Mr. Chen |
+----------+------------+----------+---------------+
3 rows in set (0.00 sec)
mysql> UPDATE class SET grade_id = 1, class_teacher = ' Miss Wu ' WHERE class_id = 3;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> SELECT * FROM class;
+----------+------------+----------+---------------+
| class_id | class_name | grade_id | class_teacher |
+----------+------------+----------+---------------+
| 1 | Class one | 1 | Teacher wang |
| 2 | Class two | 1 | Miss Xu |
| 3 | Class three | 1 | Miss Wu |
+----------+------------+----------+---------------+
3 rows in set (0.01 sec)
Replace data
REPLACE INTO Be similar to INSERT INTO sentence , But this statement can replace the existing value , If some values are unique .
- Use
UNIQUEMake the field unique
mysql> ALTER TABLE students
-> CHANGE COLUMN student_id student_id INT UNIQUE;
Query OK, 0 rows affected (0.44 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> DESC students;
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(32) | YES | | NULL | |
| birthday | date | YES | | NULL | |
| class_id | int(11) | YES | | NULL | |
| student_id | int(11) | YES | UNI | NULL | |
| address | varchar(255) | YES | | NULL | |
+------------+--------------+------+-----+---------+----------------+
6 rows in set (0.00 sec)
- Replace data
mysql> SELECT * FROM students;
+----+----------+------------+----------+------------+-----------------------------+
| id | name | birthday | class_id | student_id | address |
+----+----------+------------+----------+------------+-----------------------------+
| 1 | xiaoming | 1996-07-01 | 3 | 80301 | Xiangcheng District, Suzhou City, Jiangsu Province |
| 3 | xiaohong | 1995-09-05 | 3 | 80310 | Maanshan City, Anhui Province |
| 4 | Huang Gai | 1996-05-21 | 1 | 80102 | Wuxi City, Jiangsu Province |
| 5 | Qin Ming | 1996-03-03 | 2 | 80205 | Nanjing, jiangsu province |
+----+----------+------------+----------+------------+-----------------------------+
4 rows in set (0.01 sec)
mysql> SELECT * FROM students WHERE id = 1;
+----+----------+------------+----------+------------+-----------------------------+
| id | name | birthday | class_id | student_id | address |
+----+----------+------------+----------+------------+-----------------------------+
| 1 | xiaoming | 1996-07-01 | 3 | 80301 | Xiangcheng District, Suzhou City, Jiangsu Province |
+----+----------+------------+----------+------------+-----------------------------+
1 row in set (0.00 sec)
mysql> REPLACE INTO students
-> (name, birthday, class_id, student_id, address)
-> VALUES(' Xiao Wang ', '1997-01-02', 3, 80303, ' Suzhou City, Jiangsu Province '),
-> ('xiaoming', '1996-07-01', 3, 80301, ' Xiangcheng District, Suzhou City, Jiangsu Province ');
Query OK, 3 rows affected (0.05 sec)
Records: 2 Duplicates: 1 Warnings: 0
mysql> SELECT * FROM students;
+----+----------+------------+----------+------------+-----------------------------+
| id | name | birthday | class_id | student_id | address |
+----+----------+------------+----------+------------+-----------------------------+
| 3 | xiaohong | 1995-09-05 | 3 | 80310 | Maanshan City, Anhui Province |
| 4 | Huang Gai | 1996-05-21 | 1 | 80102 | Wuxi City, Jiangsu Province |
| 5 | Qin Ming | 1996-03-03 | 2 | 80205 | Nanjing, jiangsu province |
| 6 | Xiao Wang | 1997-01-02 | 3 | 80303 | Suzhou City, Jiangsu Province |
| 7 | xiaoming | 1996-07-01 | 3 | 80301 | Xiangcheng District, Suzhou City, Jiangsu Province |
+----+----------+------------+----------+------------+-----------------------------+
5 rows in set (0.00 sec)
mysql> REPLACE INTO students
-> (id, name, birthday, class_id, student_id, address)
-> VALUES(1, 'xiaoming', '1996-07-01', 3, 80301, ' Xiangcheng District, Suzhou City, Jiangsu Province ');
Query OK, 2 rows affected (0.00 sec)
mysql> SELECT * FROM students;
+----+----------+------------+----------+------------+-----------------------------+
| id | name | birthday | class_id | student_id | address |
+----+----------+------------+----------+------------+-----------------------------+
| 1 | xiaoming | 1996-07-01 | 3 | 80301 | Xiangcheng District, Suzhou City, Jiangsu Province |
| 3 | xiaohong | 1995-09-05 | 3 | 80310 | Maanshan City, Anhui Province |
| 4 | Huang Gai | 1996-05-21 | 1 | 80102 | Wuxi City, Jiangsu Province |
| 5 | Qin Ming | 1996-03-03 | 2 | 80205 | Nanjing, jiangsu province |
| 6 | Xiao Wang | 1997-01-02 | 3 | 80303 | Suzhou City, Jiangsu Province |
+----+----------+------------+----------+------------+-----------------------------+
5 rows in set (0.00 sec)
mysql> REPLACE INTO students
-> (name, birthday, class_id, student_id, address)
-> VALUES('huangwen', '1995-02-04', 3, 80301, ' Yancheng City, Jiangsu Province ');
Query OK, 2 rows affected (0.00 sec)
mysql> SELECT * FROM students;
+----+----------+------------+----------+------------+-----------------------+
| id | name | birthday | class_id | student_id | address |
+----+----------+------------+----------+------------+-----------------------+
| 3 | xiaohong | 1995-09-05 | 3 | 80310 | Maanshan City, Anhui Province |
| 4 | Huang Gai | 1996-05-21 | 1 | 80102 | Wuxi City, Jiangsu Province |
| 5 | Qin Ming | 1996-03-03 | 2 | 80205 | Nanjing, jiangsu province |
| 6 | Xiao Wang | 1997-01-02 | 3 | 80303 | Suzhou City, Jiangsu Province |
| 8 | huangwen | 1995-02-04 | 3 | 80301 | Yancheng City, Jiangsu Province |
+----+----------+------------+----------+------------+-----------------------+
5 rows in set (0.00 sec)
Delete data (DELETE FROM)
Subquery delete
mysql> SELECT * FROM class;
+----------+------------+----------+---------------+
| class_id | class_name | grade_id | class_teacher |
+----------+------------+----------+---------------+
| 1 | Class one | 1 | Teacher wang |
| 2 | Class two | 1 | Miss Xu |
| 3 | Class three | 1 | Miss Wu |
+----------+------------+----------+---------------+
3 rows in set (0.00 sec)
mysql> SELECT * FROM students;
+----+----------+------------+----------+------------+-----------------------+
| id | name | birthday | class_id | student_id | address |
+----+----------+------------+----------+------------+-----------------------+
| 3 | xiaohong | 1995-09-05 | 3 | 80310 | Maanshan City, Anhui Province |
| 4 | Huang Gai | 1996-05-21 | 1 | 80102 | Wuxi City, Jiangsu Province |
| 5 | Qin Ming | 1996-03-03 | 2 | 80205 | Nanjing, jiangsu province |
| 6 | Xiao Wang | 1997-01-02 | 3 | 80303 | Suzhou City, Jiangsu Province |
| 8 | huangwen | 1995-02-04 | 3 | 80301 | Yancheng City, Jiangsu Province |
+----+----------+------------+----------+------------+-----------------------+
5 rows in set (0.00 sec)
mysql> DELETE FROM students
-> WHERE class_id =
-> (SELECT c.class_id FROM class c WHERE class_teacher = ' Miss Xu ');
Query OK, 1 row affected (0.00 sec)
mysql> SELECT * FROM students;
+----+----------+------------+----------+------------+-----------------------+
| id | name | birthday | class_id | student_id | address |
+----+----------+------------+----------+------------+-----------------------+
| 3 | xiaohong | 1995-09-05 | 3 | 80310 | Maanshan City, Anhui Province |
| 4 | Huang Gai | 1996-05-21 | 1 | 80102 | Wuxi City, Jiangsu Province |
| 6 | Xiao Wang | 1997-01-02 | 3 | 80303 | Suzhou City, Jiangsu Province |
| 8 | huangwen | 1995-02-04 | 3 | 80301 | Yancheng City, Jiangsu Province |
+----+----------+------------+----------+------------+-----------------------+
4 rows in set (0.00 sec)
Query setting variable deletion
mysql> SET @class_id =
-> (SELECT class_id FROM class WHERE class_teacher = ' Miss Xu ');
Query OK, 0 rows affected (0.00 sec)
mysql> DELETE FROM students
-> WHERE class_id = @class_id;
Query OK, 0 rows affected (0.00 sec)
Select data (SELECT)
Full column query (SELECT *)
SELECT * FROM table_name
mysql> SELECT * FROM students;
+----+----------+-----------+----------+------------+-----------------------------+
| id | name | birthday | class_id | student_id | address |
+----+----------+------+------------+----------+------------+-----------------------------+
| 1 | xiaoming | 1996-07-01 | 3 | 80301 | Xiangcheng District, Suzhou City, Jiangsu Province |
| 3 | xiaohong |1995-09-05 | 3 | 80310 | Maanshan City, Anhui Province |
| 4 | Huang Gai | 1996-05-21 | 1 | 80102 | Wuxi City, Jiangsu Province |
| 5 | Qin Ming | 1996-03-03 | 2 | 80205 | Nanjing, jiangsu province |
+----+----------+------+------------+----------+------------+-----------------------------+
4 rows in set (0.00 sec)
Select column query (SELECT col)
SELECT col1_name, col4_name FROM table_name WHERE col3_name = 'valuexxx';
mysql> SELECT name, student_id FROM students WHERE class_id = 3;
+----------+------------+
| name | student_id |
+----------+------------+
| xiaoming | 80301 |
| xiaohong | 80310 |
+----------+------------+
2 rows in set (0.00 sec)
Table Association query (JOIN USING)
JOIN ... USING,USING Used for queries with the same column values in two tables . And use CONCAT(str1, str2, ...) String splicing
mysql> SELECT name, birthday, address,
-> CONCAT(grade_id, ' grade ', class_name) AS class_info
-> FROM students
-> JOIN class USING(class_id)
-> WHERE class_teacher = ' Miss Wu ';
+----------+------------+-----------------------------+---------------+
| name | birthday | address | class_info |
+----------+------------+-----------------------------+---------------+
| xiaoming | 1996-07-01 | Xiangcheng District, Suzhou City, Jiangsu Province | 1 Class 3, grade |
| xiaohong | 1995-09-05 | Maanshan City, Anhui Province | 1 Class 3, grade |
+----------+------------+-----------------------------+---------------+
2 rows in set (0.00 sec)
Sort (ORDER BY)
Ascending
Ascending order is used by default
mysql> SELECT * FROM students ORDER BY birthday;
+----+----------+------------+----------+------------+-----------------------------+
| id | name | birthday | class_id | student_id | address |
+----+----------+------------+----------+------------+-----------------------------+
| 3 | xiaohong | 1995-09-05 | 3 | 80310 | Maanshan City, Anhui Province |
| 5 | Qin Ming | 1996-03-03 | 2 | 80205 | Nanjing, jiangsu province |
| 4 | Huang Gai | 1996-05-21 | 1 | 80102 | Wuxi City, Jiangsu Province |
| 1 | xiaoming | 1996-07-01 | 3 | 80301 | Xiangcheng District, Suzhou City, Jiangsu Province |
+----+----------+------------+----------+------------+-----------------------------+
4 rows in set (0.00 sec)
Descending
Use DESC In descending order
mysql> SELECT * FROM students ORDER BY birthday DESC;
+----+----------+------------+----------+------------+-----------------------------+
| id | name | birthday | class_id | student_id | address |
+----+----------+------------+----------+------------+-----------------------------+
| 1 | xiaoming | 1996-07-01 | 3 | 80301 | Xiangcheng District, Suzhou City, Jiangsu Province |
| 4 | Huang Gai | 1996-05-21 | 1 | 80102 | Wuxi City, Jiangsu Province |
| 5 | Qin Ming | 1996-03-03 | 2 | 80205 | Nanjing, jiangsu province |
| 3 | xiaohong | 1995-09-05 | 3 | 80310 | Maanshan City, Anhui Province |
+----+----------+------------+----------+------------+-----------------------------+
4 rows in set (0.00 sec)
Limit (LIMIT)
Limit number
LIMIT n Limit n Exhibition
mysql> SELECT * FROM students LIMIT 2;
+----+----------+------------+----------+------------+-----------------------------+
| id | name | birthday | class_id | student_id | address |
+----+----------+------------+----------+------------+-----------------------------+
| 1 | xiaoming | 1996-07-01 | 3 | 80301 | Xiangcheng District, Suzhou City, Jiangsu Province |
| 3 | xiaohong | 1995-09-05 | 3 | 80310 | Maanshan City, Anhui Province |
+----+----------+------------+----------+------------+-----------------------------+
2 rows in set (0.01 sec)
Skip the limit
LIMIT(m, n), skip m individual , Behind the show n individual .
mysql> SELECT * FROM students LIMIT 2, 1;
+----+--------+------------+----------+------------+--------------------+
| id | name | birthday | class_id | student_id | address |
+----+--------+------------+----------+------------+--------------------+
| 4 | Huang Gai | 1996-05-21 | 1 | 80102 | Wuxi City, Jiangsu Province |
+----+--------+------------+----------+------------+--------------------+
1 row in set (0.00 sec)
Fuzzy query
Use LIKE and % Fuzzy matching
mysql> SELECT `name`, birthday, address
-> FROM students
-> WHERE address LIKE '% jiangsu %';
+----------+------------+--------------------+
| name | birthday | address |
+----------+------------+--------------------+
| Huang Gai | 1996-05-21 | Wuxi City, Jiangsu Province |
| Xiao Wang | 1997-01-02 | Suzhou City, Jiangsu Province |
| huangwen | 1995-02-04 | Yancheng City, Jiangsu Province |
+----------+------------+--------------------+
3 rows in set (0.00 sec)
Intersection and union query
- Use
ANDPerform intersection query
mysql> SELECT `name`, birthday, address
-> FROM students
-> WHERE address LIKE '% jiangsu %' AND class_id = 1;
+--------+------------+--------------------+
| name | birthday | address |
+--------+------------+--------------------+
| Huang Gai | 1996-05-21 | Wuxi City, Jiangsu Province |
+--------+------------+--------------------+
1 row in set (0.00 sec)
- Use
ORPerform union query
mysql> SELECT `name`, birthday, address
-> FROM students
-> WHERE `name` LIKE '%xiao%' OR `name` LIKE '% Small %';
+----------+------------+-----------------------+
| name | birthday | address |
+----------+------------+-----------------------+
| xiaohong | 1995-09-05 | Maanshan City, Anhui Province |
| Xiao Wang | 1997-01-02 | Suzhou City, Jiangsu Province |
+----------+------------+-----------------------+
2 rows in set (0.00 sec)
Analyze and process data
Number of Statistics (COUNT)
COUNT(*) function
mysql> SELECT COUNT(*)
-> FROM students
-> JOIN class USING (class_id)
-> WHERE class_name = ' Class three ';
+----------+
| COUNT(*) |
+----------+
| 2 |
+----------+
1 row in set (0.00 sec)
Sum function (SUM)
SUM(col_name)
mysql> SELECT SUM(grade_id) AS 'grade_sum'
-> FROM class
-> JOIN students USING (class_id);
+-----------+
| grade_sum |
+-----------+
| 4 |
+-----------+
1 row in set (0.00 sec)
Date processing
function : month MONTHNAME(col_name), Japan DAYOFMONTH(col_name), year YEAR(col_name)
mysql> SELECT CONCAT(MONTHNAME(birthday), ' ',
-> DAYOFMONTH(birthday), ',',
-> YEAR(birthday)) AS student_birthday
-> FROM students
-> WHERE `name` = 'xiaoming';
+------------------+
| student_birthday |
+------------------+
| July 1,1996 |
+------------------+
1 row in set (0.00 sec)
function DATE_FORMAT(col_name, "%M %d, %Y")
mysql> SELECT DATE_FORMAT(birthday, "%M %d, %Y")
-> AS 'student_birth_date'
-> FROM students
-> WHERE `name` = 'xiaohong';
+--------------------+
| student_birth_date |
+--------------------+
| September 05, 1995 |
+--------------------+
1 row in set (0.00 sec)
Bulk import data (LOAD DATA INFILE)
- mysql File directory
mysql> SHOW VARIABLES LIKE '%secure_file_priv%';
+------------------+-----------------------+
| Variable_name | Value |
+------------------+-----------------------+
| secure_file_priv | /var/lib/mysql-files/ |
+------------------+-----------------------+
1 row in set (0.00 sec)
- establish txt file
[[email protected] /var/lib/mysql-files] touch sql_data.txt
[[email protected] /var/lib/mysql-files] vim sql_data.txt
[[email protected] /var/lib/mysql-files]# cat sql_data.txt
name | birthday | class_id | student_id |address|
xiaow| 1995-09-05|3|80310|anhui|
xiaoh| 1996-05-01|2|80209|zhejiang|
- Import
mysql> LOAD DATA INFILE '/var/lib/mysql-files/sql_data.txt'
-> REPLACE INTO TABLE students
-> FIELDS TERMINATED BY '|' LINES TERMINATED BY '\n' IGNORE 1 LINES
-> (`name`, birthday, class_id, student_id, address);
Query OK, 2 rows affected (0.01 sec)
Records: 2 Deleted: 0 Skipped: 0 Warnings: 0
mysql> SELECT * FROM students;
+------+-------+------------+----------+------------+----------+
| id | name | birthday | class_id | student_id | address |
+------+-------+------------+----------+------------+----------+
| 1| xiaow | 1995-09-05 | 3 | 80310 | anhui |
| 2 | xiaoh | 1996-05-01 | 2 | 80209 | zhejiang |
+------+-------+------------+----------+------------+----------+
2 rows in set (0.00 sec)
边栏推荐
- MySQL优化总结二
- UIDocumentInteractionController UIDocumentPickerViewController
- mouseover和mouseenter的区别
- 带你详细认识JS基础语法(建议收藏)
- Use cpolar to build a business website (how to buy a domain name)
- Geogle Colab笔记1--运行Geogle云端硬盘上的.py文件
- Understanding the difference between wait() and sleep()
- Word 样式模板复制到另一文档
- CF750F1-思维dp
- MATLAB 如何生产随机复序列
猜你喜欢

IDEA—点击文件代码与目录自动同步对应

MySQL transactions and mvcc

matlab 优化工具 manopt 安装

Pytorch学习笔记--常用函数总结3

LeetCode - 225 用队列实现栈

Games101 review: 3D transformation

解决vender-base.66c6fc1c0b393478adf7.js:6 TypeError: Cannot read property ‘validate‘ of undefined问题

JVM - classloader and parental delegation model

Pytorch学习笔记-刘二老师RNN高级篇-代码注释及结果

ML - natural language processing - Introduction to natural language processing
随机推荐
IOS interview questions
<栈模拟递归>
MySQL优化总结二
Qtime定义(手工废物利用简单好看)
GAMES101复习:线性代数
C#精挑整理知识要点10 泛型(建议收藏)
MySQL—常用SQL语句整理总结
C # fine sorting knowledge points 10 generic (recommended Collection)
Gary Marcus: 学习语言比你想象的更难
CF685B-求有根树每颗子树的重心
2021hncpc-e-difference, thinking
JVM—类加载器和双亲委派模型
Idea eye care settings
2016 CCPC network trial c-change root DP good question
Xcode添加mobileprovision证书文件报错:Xcode encountered an error
No tracked branch configured for branch xxx or the branch doesn‘t exist. To make your branch trac
2021 Jiangsu race a Array line segment tree, maintain value range, Euler power reduction
HDU3873-有依赖的最短路(拓扑排序)
谷歌云盘如何关联Google Colab
Cf685b find the center of gravity of each subtree of a rooted tree