当前位置:网站首页>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
边栏推荐
- 毕业季|与青春作伴,一起向未来!
- Add a self incrementing sequence number to the antd table component
- Input type= "password" how to solve the problem of password automatically brought in
- There are ways to improve self-discipline and self-control
- The opacity value becomes 1%
- uniCloud
- How to use cherry pick?
- The use of list and Its Simulation Implementation
- What if copying is prohibited?
- Go redis Middleware
猜你喜欢
LeetCode - 面试题17.24 最大子矩阵
Table replication in PostgreSQL
Verilog 实现数码管显视驱动【附源码】
[C #] the solution of WinForm operation zoom (blur)
How to use cherry pick?
[untitled]
聊聊SOC启动(十一) 内核初始化
MPX plug-in
Seata 1.3.0 four modes to solve distributed transactions (at, TCC, Saga, XA)
[pyqt] the cellwidget in tablewidget uses signal and slot mechanism
随机推荐
MPX plug-in
面试被问到了解哪些开发模型?看这一篇就够了
Verilog design responder [with source code]
How to use cherry pick?
[untitled]
Seata 1.3.0 four modes to solve distributed transactions (at, TCC, Saga, XA)
The concept, implementation and analysis of binary search tree (BST)
Hash / (understanding, implementation and application)
Graduation season | keep company with youth and look forward to the future together!
RationalDMIS2022 高级编程宏程序
A case of compiling QT file qmake compiling script
聊聊SOC启动(七) uboot启动流程三
The sixth training assignment
Briefly introduce closures and some application scenarios
分布式数据库主从配置(MySQL)
VIM命令模式与输入模式切换
什么是高内聚、低耦合?
Ping tool ICMP message learning
Distributed database master-slave configuration (MySQL)
對比學習之 Unsupervised Learning of Visual Features by Contrasting Cluster Assignments