Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
development:database [2020/03/05 11:14]
kalenpw
— (current)
Line 1: Line 1:
-====== Database ====== 
-These are all for MySQL 
  
- 
-===== Cleaner Terminal Output ===== 
-MySQL can have quite messy output when running queries from the ''mysql'' cli. You can terminate a statement with ''\G'' instead of '';'' to format as a list instead of table. 
-<code mysql> 
-SELECT * FROM users\G 
-</code> 
- 
-Alternatively, you can set the pager to ''less'' which retains the table format and can be scrolled with arrowkeys. 
-<code mysql> 
-pager less -SFX 
-SELECT * FROM users; 
-nopager; -- to turn off 
-</code> 
- 
- 
-===== Grant permissions ===== 
-replace ''*.*'' with ''schema.table'' if needed 
-<code mysql> 
-GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost'; 
-</code> 
- 
- 
-===== Basic syntax ===== 
-==== update ==== 
-<code mysql> 
-UPDATE employees SET email = 'user@domain.com' WHERE id = 123; 
-</code> 
- 
- 
-===== Many to Many Relationship Joins ===== 
-<code mysql> 
-SELECT  
-  a.* 
-FROM  
-  map_ads_categories m 
-  JOIN ads a ON (m.ad_id = a.id) 
-WHERE 
-  m.category_id = 28; 
-</code> 
-<code mysql> 
-SELECT  
-  * 
-FROM  
-  map_ads_categories m 
-  JOIN ads a ON (m.ad_id = a.id) 
-  JOIN categories c ON (m.category_id = c.id) 
-WHERE 
-  c.id = 28; 
-</code>