Friday, May 7, 2021

MySQL CLI

 Command Format and Usage

======================== 

 

* Environment variables has lower precedence over command-line options 

* "-" and "_" can be interchanged 

  example: --skip-grant-tables and --skip_grant_tables are the same 

* Last option takes precedence 

  example: shell> mysql --column-names --skip-column-names 

* Long form options can be written as: --long-option=value 

* For long options which don't have a default value, "=" is not required 

  e.g: mysql --host tonfisk --user jon 

* Options having default values always required "=" sign 

  e.g: mysqld_safe --log-error=my-errors &  # default value is `hostname.err` 

* Here are some invalid formats: 

    mysql --host 85.224.35.45 --user 

    mysql --host --user jon 

 

 

Program Options Modifier 

======================== 

 

Options with same effect 

--disable-column-names 

--skip-column-names 

--column-names=0 

 

or 

 

--column-names 

--enable-column-names 

--column-names=1 

Ignoring non-existent 

options 

Adding "--loose" prior to an option makes mysql ignore non-existent options. 

 

Example, this provides a valid option: 
 

[ansible@mysql ~]$ mysql --loose-skip-column-names -e "select * from pets.pet;" 

+----------+-----------+---------+------+------------+------------+ 

| Whistler |      Gwen |    bird | NULL | 1997-12-09 |       NULL | 

|   Gunner |      Mark |     dog |    m | 1992-01-14 |       NULL | 

|    Heath | Stephanie | penguin |    m | 2001-12-12 |       NULL | 

|  Winnona | Stephanie |     dog |    m | 2009-03-18 |       NULL | 

|   Hunter | Stephanie |    fish |    f | 1997-09-21 |       NULL | 

| Splitter |      Gwen |    fish |    m | 1996-01-12 | 1999-03-04 | 

|   Styder |      Gwen |    fish |    f | 2018-05-17 |       NULL | 

+----------+-----------+---------+------+------------+------------+ 
 
While this one doesn't but MySQL just ignores it. 

 

[ansible@mysql ~]$ mysql --loose-skip-columns-names -e "select * from pets.pet;" 

mysql: [Warning] unknown option '--loose-skip-columns-names' 

+----------+-----------+---------+------+------------+------------+ 

| name     | owner     | species | sex  | birth      | death      | 

+----------+-----------+---------+------+------------+------------+ 

| Whistler | Gwen      | bird    | NULL | 1997-12-09 | NULL       | 

| Gunner   | Mark      | dog     | m    | 1992-01-14 | NULL       | 

| Heath    | Stephanie | penguin | m    | 2001-12-12 | NULL       | 

| Winnona  | Stephanie | dog     | m    | 2009-03-18 | NULL       | 

| Hunter   | Stephanie | fish    | f    | 1997-09-21 | NULL       | 

| Splitter | Gwen      | fish    | m    | 1996-01-12 | 1999-03-04 | 

| Styder   | Gwen      | fish    | f    | 2018-05-17 | NULL       | 

+----------+-----------+---------+------+------------+------------+ 

[ansible@mysql ~]$ 

 

This is helpful if you are executing a command over different versions of MySQL. 
That guarantees that your command will not terminate when an invalid options 

is detected. 

Setting max sizes 

"--maximum-max_heap_table_size=32M" prevents any client from making the heap 

table size limit larger than 32M. 

 

No comments:

Post a Comment