当前位置:网站首页>Common SQL statement collation: MySQL
Common SQL statement collation: MySQL
2022-07-07 11:24:00 【Full stack programmer webmaster】
## Commonly used sql Sentence arrangement :mysql
1. increase
– Add a table “` CREATE TABLE `table_name`( … )ENGINE=InnoDB DEFAULT CHARSET=utf8; “`
– Increase record “` INSERT INTO `your_table_name`(`column_name`) VALUES (‘your_value_one’), (‘your_value_two’); “`
– Add fields “` ALTER TABLE `your_table_name` ADD `your_column_name` … AFTER `column_name`; “`
– Add index + Primary key “` ALTER TABLE `your_table_name` ADD PRIMARY KEY your_index_name(your_column_name); “` + unique index “` ALTER TABLE `your_table_name` ADD UNIQUE your_index_name(your_column_name); “` + General index “` ALTER TABLE `your_table_name` ADD INDEX your_index_name(your_column_name); “` + Full-text index “` ALTER TABLE `your_table_name` ADD FULLTEXT your_index_name(your_column_name); “`
2. Delete
– Delete line by line “` DELETE FORM `table_name` WHERE …; “`
– Clear the whole table “` TRUNCATE TABLE `your_table_name`; “`
– Delete table “` DROP TABLE `your_table_name`; “`
– Delete field “` ALTER TABLE `your_table_name` DROP `column_name`; “`
– Delete index “` ALTER TABLE `your_table_name` DROP INDEX your_index_name(your_column_name); “`
3. Change
– Change data “` UPDATE `table_name` SET column_name=your_value WHERE …; “`
– Change field “` ALTER TABLE `your_table_name` CHANGE `your_column_name` `your_column_name` …( change ); “`
– Change the field value to a value in another table “` UPDATE `your_table_name` AS a JOIN `your_anther_table_name` AS b SET a.column = b.anther_column WHERE a.id = b.a_id…; “`
4. check
– Common query “` SELECT `column_name_one`, `column_name_two` FROM `table_name`; “`
– Relational query “` SELECT * FROM `your_table_name` AS a JOIN `your_anther_table_name` AS b WHERE a.column_name = b.column_name…; “`
– Total function condition query :WHERE Keyword cannot be used with aggregate function “` SELECT aggregate_function(column_name) FROM your_table_name GROUP BY column_name HAVING aggregate_function(column_name)…; “`
– Cross database query under the same instance “` SELECT * FROM database_name.your_table_name AS a JOIN another_database_name.your_another_table_name AS b WHERE a.column_name = b.column_name…; “`
5. Copy a table structure “` CREATE TABLE `your_table_name` LIKE `destination_table_name`; “`
6. Copy a table completely : Table structure + All data “` CREATE TABLE `your_table_name` LIKE `destination_table_name`;
INSERT INTO `your_table_name` SELECT * FROM `destination_table_name`; “`
—
### appendix :mysql Common commands – land : mysql -h host -u username -p – List databases :SHOW DATABESES; – List tables :SHOW TABLES; – List table structure :DESC table_name – Use a database :USE database_name; – Import :source ‘file’; – export :mysqldump -h 127.0.0.1 -u root -p “database_name” “table_name” –where=”condition” > file_name.sql; – Check the slow log :mysqldumpslow -s [c: Sort by number of records /t: Time /l: Lock time /r: Number of records returned ] -t [n: front n Data ] -g “ Regular ” /path – New users : insert into `user`(`Host`, `User`, `authentication_string`) value(‘localhost’, ‘username’, password(‘pwd’))
### mysql 5.7 New users
“` // Insert a new user insert into mysql.user(Host, User, authentication_string, ssl_cipher, x509_issuer, x509_subject value(‘localhost’, ‘username’, password(‘password’), ”, ”, ”);
// Database authorization grant all privileges on dbname.name.* to [email protected] identified by ‘password’;
// Refresh permission information FLUSH PRIVILEGES; “`
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/113828.html Link to the original text :https://javaforall.cn
边栏推荐
- Network foundation (1)
- Android 面试知识点
- 数据库同步工具 DBSync 新增对MongoDB、ES的支持
- Verilog 实现数码管显视驱动【附源码】
- QT | multiple windows share a prompt box class
- PostgreSQL中的表复制
- [pyqt] the cellwidget in tablewidget uses signal and slot mechanism
- STM32入门开发 编写DS18B20温度传感器驱动(读取环境温度、支持级联)
- Learning notes | data Xiaobai uses dataease to make a large data screen
- electron添加SQLite数据库
猜你喜欢
![[untitled]](/img/c7/b6abe0e13e669278aea0113ca694e0.jpg)
[untitled]

LeetCode - 面试题17.24 最大子矩阵

Array object sorting
![Verilog design responder [with source code]](/img/91/6359a2f3fa0045b4a88956a475488c.png)
Verilog design responder [with source code]

Input type= "password" how to solve the problem of password automatically brought in

数据库同步工具 DBSync 新增对MongoDB、ES的支持

分布式数据库主从配置(MySQL)

Distributed database master-slave configuration (MySQL)

About the application of writing shell script JSON in JMeter

What if copying is prohibited?
随机推荐
面试被问到了解哪些开发模型?看这一篇就够了
OneDNS助力高校行业网络安全
The sixth training assignment
在我有限的软件测试经历里,一段专职的自动化测试经验总结
深度学习秋招面试题集锦(一)
從色情直播到直播電商
【问道】编译原理
Multithreaded application (thread pool, singleton mode)
Briefly introduce closures and some application scenarios
【愚公系列】2022年7月 Go教学课程 005-变量
Wallhaven wallpaper desktop version
PR Lecture Notes
[untitled]
oracle常见锁表处理方式
Template initial level template
基于Retrofit框架的金山API翻译功能案例
Seata 1.3.0 four modes to solve distributed transactions (at, TCC, Saga, XA)
聊聊SOC启动(十一) 内核初始化
What if copying is prohibited?
Activity lifecycle