MySQL 是一種關系型數據庫管理系統,因其簡單易用和高效性受到廣泛的應用。下面介紹一些 MySQL 常見的命令和語法:
1. 連接數據庫 $ mysql -u username -p 密碼 2. 創建數據庫 CREATE DATABASE databasename; 3. 選擇數據庫 USE databasename; 4. 創建表格 CREATE TABLE tablename ( field1 datatype constraint, field2 datatype constraint, … ); 5. 查看表格 DESCRIBE tablename; 6. 插入數據 INSERT INTO tablename (field1, field2, …) VALUES (value1, value2, …); 7. 更新數據 UPDATE tablename SET field1=value1, field2=value2, … WHERE condition; 8. 刪除數據 DELETE FROM tablename WHERE condition; 9. 選擇數據 SELECT field1, field2, … FROM tablename WHERE condition GROUP BY field HAVING condition ORDER BY field ASC/DESC; 10. 清空表格 TRUNCATE tablename; 11. 刪除表格 DROP TABLE tablename; 12. 連接表格 SELECT * FROM tab1 INNER JOIN tab2 ON tab1.col1 = tab2.col2; 13. 創建索引 CREATE INDEX indexname ON tablename (columnname); 14. 刪除索引 DROP INDEX indexname ON tablename;