MySQL¶
Install MySQL server¶
MacOS¶
Download MySQL Community Server
https://dev.mysql.com/downloads/mysql/
Debian¶
See https://superuser.com/a/1481211
Other¶
- Go to https://dev.mysql.com/downloads/shell/ and download
- add to path
export PATH=/usr/local/mysql/bin:$PATH
- to connect
mysql -u root -p
GUI¶
MySQL Workbench¶
for mac
for others, go to webpage and download
https://dev.mysql.com/downloads/workbench/
Try downgrading if there are some weird errors
Commands¶
Connect to database¶
Notice there's no space after -p
and port is specified with -P
Make output readable¶
Just type it
Query¶
- show databases
show database
- go into a database
use <db name>
- show table schema
show columns from <table name>
Upsert¶
Use the ON DUPLICATE KEY UPDATE
clause for upserting.
However, you cannot specify your own key to lookup, but only the a UNIQUE index or PRIMARY KEY will be checked.
Alter¶
alter column type¶
Troubleshooting¶
mysql workbench keeps crashing¶
Try downgrading
See https://developer.apple.com/forums/thread/724378
Failed to open file error: 2¶
If you use source path/to/file.sql
please do not enclose the file name with "