当前位置:网站首页>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
边栏推荐
猜你喜欢

普通测试年薪15w,测试开发年薪30w+,二者差距在哪?

聊聊SOC启动(十) 内核启动先导知识

From pornographic live broadcast to live broadcast E-commerce

What is cloud computing?

Ping tool ICMP message learning

基于DE2 115开发板驱动HC_SR04超声波测距模块【附源码】

关于测试人生的一站式发展建议

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

测试开发基础,教你做一个完整功能的Web平台之环境准备

The opacity value becomes 1%
随机推荐
Still cannot find RPC dispatcher table failed to connect in virtual KD
The seventh training assignment
About the application of writing shell script JSON in JMeter
JS add spaces to the string
Hash / (understanding, implementation and application)
QT implements the delete method of the container
Bookmarking - common website navigation for programmers
Verilog realizes nixie tube display driver [with source code]
Basic knowledge of process (orphan, zombie process)
关于测试人生的一站式发展建议
软件设计之——“高内聚低耦合”
博客搬家到知乎
JS array delete the specified element
V-for img SRC rendering fails
Mpx 插件
网络协议 概念
Seata 1.3.0 four modes to solve distributed transactions (at, TCC, Saga, XA)
The sixth training assignment
Deconstruction and assignment of variables
[untitled]