Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
computer_science:databases:mysql:mysql_tips_trics [2021/03/07 17:04] – [Enforce Data Integrity at the DB Level] carlossousa | computer_science:databases:mysql:mysql_tips_trics [2023/12/01 12:07] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 11: | Line 11: | ||
**Example: | **Example: | ||
< | < | ||
+ | |||
ALTER TABLE table_name ADD INDEX index_name (column); | ALTER TABLE table_name ADD INDEX index_name (column); | ||
</ | </ | ||
- | |||
===== Enforce Data Integrity at the DB Level ===== | ===== Enforce Data Integrity at the DB Level ===== | ||
Line 23: | Line 23: | ||
**Cons:** - | **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: | ||
- | **Instead of:** | ||
< | < | ||
- | posts table | + | general_log_file = / |
- | - post_id | + | general_log = 1 |
- | - title | + | |
- | - author_name | + | |
</ | </ | ||
- | **Do:** | + | check log with: |
< | < | ||
- | posts table | + | tail -f / |
- | - post_id | + | |
- | - title | + | |
- | - author_id | + | |
- | authors table | + | </ |
- | - author_id | + | ===== Use Transactions for bulk insert: ===== |
- | - name | + | |
+ | **Pros:** Only one re-index, at the end of the transaction. | ||
+ | |||
+ | **Cons: **Visibility of new data only after commit | ||
+ | |||
+ | **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; | ||
</ | </ | ||