Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| engineering:computer_science:databases:mysql:mysql_tips_trics [2024/08/16 13:56] – removed - external edit (Unknown date) 127.0.0.1 | engineering:computer_science:databases:mysql:mysql_tips_trics [2024/08/16 13:56] (current) – ↷ Links adapted because of a move operation carlossousa | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== MySQL Tips & Tricks ====== | ||
| + | |||
| + | Part of [[engineering: | ||
| + | |||
| + | ===== Use Indexes ===== | ||
| + | |||
| + | **Pros:** Massive increase in searching performance. | ||
| + | |||
| + | **Cons:** Slightly Increase in Storage Requirements. Slightly Increase on Write speeds. | ||
| + | |||
| + | **Example: | ||
| + | < | ||
| + | |||
| + | ALTER TABLE table_name ADD INDEX index_name (column); | ||
| + | |||
| + | </ | ||
| + | |||
| + | ===== Enforce Data Integrity at the DB Level ===== | ||
| + | |||
| + | **Eg.: **unique constraints, | ||
| + | |||
| + | **Pros: **Application agnostic Data Integrity | ||
| + | |||
| + | **Cons:** - | ||
| + | ===== Log Queries in Development ===== | ||
| + | |||
| + | **Pros: **Great to see Queries happening in Real Time | ||
| + | |||
| + | **Cons: **Slightly higher storage requirement | ||
| + | |||
| + | Don't forget to disable in Production | ||
| + | |||
| + | **Usage:** | ||
| + | |||
| + | Update my.cnf and add / change: | ||
| + | |||
| + | < | ||
| + | general_log_file = / | ||
| + | general_log = 1 | ||
| + | |||
| + | </ | ||
| + | |||
| + | check log with: | ||
| + | |||
| + | < | ||
| + | tail -f / | ||
| + | |||
| + | </ | ||
| + | ===== Use Transactions for bulk insert: ===== | ||
| + | |||
| + | **Pros:** Only one re-index, at the end of the transaction. | ||
| + | |||
| + | **Cons: **Visibility of new data only after commit - this can be considered an upside -. | ||
| + | |||
| + | **Usage:** | ||
| + | < | ||
| + | START transaction; | ||
| + | insert into table values (default, 1); | ||
| + | insert into table values (default, 2); | ||
| + | insert into table values (default, 3); | ||
| + | insert into table values (default, 4); | ||
| + | insert into table values (default, 5); | ||
| + | COMMIT; | ||
| + | |||
| + | </ | ||
| + | |||