MySQL數據庫是一款開源的關系型數據庫管理系統,廣泛應用于Web應用程序的開發中。在使用MySQL數據庫時,必須掌握其各種操作語句才能充分發揮其功能。以下是MySQL數據庫操作語句大全。
# 連接MySQL數據庫 mysql -h host -u user -p password # 創建數據庫 CREATE DATABASE database_name; # 刪除數據庫 DROP DATABASE database_name; # 查看所有數據庫 SHOW DATABASES; # 使用數據庫 USE database_name; # 查看所有表 SHOW TABLES; # 創建表 CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, ..... ); # 刪除表 DROP TABLE table_name; # 查看表結構 DESC table_name; # 修改表結構 ALTER TABLE table_name ADD column_name datatype; # 插入數據 INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...); # 更新數據 UPDATE table_name SET column_name = value WHERE condition; # 刪除數據 DELETE FROM table_name WHERE condition; # 查詢數據 SELECT column1, column2, ... FROM table_name WHERE condition; # 排序 SELECT * FROM table_name ORDER BY column_name; # 分組 SELECT column_name, COUNT(*) FROM table_name GROUP BY column_name; # 連接 SELECT * FROM table1 JOIN table2 ON condition; # 子查詢 SELECT * FROM table_name WHERE column_name IN (SELECT column_name FROM table_name WHERE condition); # 視圖 CREATE VIEW view_name AS SELECT column1, column2, ... FROM table_name WHERE condition; # 存儲過程 CREATE PROCEDURE procedure_name (parameter1 datatype, parameter2 datatype, ...) BEGIN ... END; # 觸發器 CREATE TRIGGER trigger_name BEFORE|AFTER INSERT|UPDATE|DELETE ON table_name FOR EACH ROW BEGIN ... END; # 索引 CREATE INDEX index_name ON table_name(column_name); # 查看索引 SHOW INDEX FROM table_name; # 刪除索引 DROP INDEX index_name ON table_name;
以上就是MySQL數據庫操作語句大全,不同的語句可以組合使用來完成各種復雜的任務,掌握這些語句對于MySQL數據庫的使用至關重要。