MySQL

Some common MySQL commands

Joining 2 tables on some columns

mysql> select T1.training_data_set_id, T1.food_aws_url from \
_training_data_set as T1, _observation_data as T2 \
where T2.source like '%<source-name>' and T2.training_data_set_id=T1.training_data_set_id;

mysql> SELECT T1.inserted_date, T1.training_data_set_id, T1.food_aws_url, T1.annotate_file_url, \
T3.commodity FROM _training_data_set as T1, _observation_data as \
T2, _training_commodity_variety as T3 where T2.source='<source-name>' \
and T2.training_data_set_id=T1.training_data_set_id and T1.training_data_set_id=T3.training_data_set_id \
and T3.commodity='blueberry';

mysql> SELECT T1.inserted_date, T1.training_data_set_id, T1.food_aws_url, T1.annotate_file_url, \
T3.commodity FROM _training_data_set as T1, _observation_data as T2, \
_training_commodity_variety as T3 where T2.source='<source-name>';

# to connect multiple tables and also use pattern search using 'like'
mysql> select tds.training_data_set_id from _training_commodity_variety as tcv, \
_training_data_set as tds  where tds.training_data_set_id=tcv.training_data_set_id and \
tcv.commodity="strawberry-IU" and tcv.variety="green" and food_aws_url like '%_top_0%';

To see the structure of the table

To find all the tables that have the 'delete cascade on' set on the FK

Ref: http://www.mysqltutorial.org/mysql-on-delete-cascade/

To get to the EC2 MySQL from Mac terminal as root

To copy database

To get csv file from command line

To drop database

To DROP table

To create table

To update table

Other commands on table

To CREATE USER and grant privileges

To change GRANT Privileges

To DELETE data from table

Last updated

Was this helpful?