当前位置:网站首页>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
边栏推荐
- 聊聊SOC启动(六)uboot启动流程二
- Basic knowledge of process (orphan, zombie process)
- [untitled]
- Web端自动化测试失败的原因
- Apprentissage comparatif non supervisé des caractéristiques visuelles par les assignations de groupes de contrôle
- 2021-04-23
- About the application of writing shell script JSON in JMeter
- Rolling puddle Uni_ App (VIII)
- Learning notes | data Xiaobai uses dataease to make a large data screen
- Avoid mutating a prop directly since the value will be overwritten whenever the parent component
猜你喜欢
The opacity value becomes 1%
关于jmeter中编写shell脚本json的应用
Leetcode - interview question 17.24 maximum submatrix
面试被问到了解哪些开发模型?看这一篇就够了
Seata 1.3.0 four modes to solve distributed transactions (at, TCC, Saga, XA)
LeetCode - 面试题17.24 最大子矩阵
使用MeterSphere让你的测试工作持续高效
学习笔记|数据小白使用DataEase制作数据大屏
Force buckle 1002 Find common characters
The database synchronization tool dbsync adds support for mongodb and es
随机推荐
[encapsulation of time format tool functions]
electron添加SQLite数据库
QT | multiple windows share a prompt box class
Add a self incrementing sequence number to the antd table component
毕业季|与青春作伴,一起向未来!
Using ENSP to do MPLS pseudo wire test
RationalDMIS2022阵列工件测量
Still cannot find RPC dispatcher table failed to connect in virtual KD
Idea shortcut keys
【时间格式工具函数的封装】
创意信息获2家机构调研:GreatDB 数据库已在9地部署
After the uniapp jumps to the page in onlaunch, click the event failure solution
The opacity value becomes 1%
TDengine 社区问题双周精选 | 第二期
2021-04-08
uniapp 在onLaunch中跳轉頁面後,點擊事件失效解决方法
Creative information was surveyed by 2 institutions: greatdb database has been deployed in 9 places
‘module‘ object is not callable错误
学习笔记|数据小白使用DataEase制作数据大屏
Web端自动化测试失败的原因