Tuesday, May 4, 2021

MySQL Program

Using MySQL with Apache 

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

 

Add this to apache config: 

 

LogFormat \ 

        "\"%h\",%{%Y%m%d%H%M%S}t,%>s,\"%b\",\"%{Content-Type}o\",  \ 

        \"%U\",\"%{Referer}i\",\"%{User-Agent}i\"" 

 

Then you can load the log file into a MySQL table: 

 

LOAD DATA INFILE '/local/access_log' INTO TABLE tbl_name 

FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\' 

 

Overview of MySQL Programs 

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

 

server programs: 

 

mysqld - main server program 

mysqld_safe - used to launch mysql 

mysql.server 

mysqld_multi 

 

programs for setting up, installing, or upgading mysql: 

 

comp_err 

mysql_install_db 

mysql_plugin 

mysql_secure_installation 

mysql_ssl_rsa_setup 

mysql_tzinfo_to_sql 

mysql_upgrade 

 

client programs that connect to MySQL server: 

 

mysql 

mysqladmin 

mysqlcheck 

mysqldump 

mysqlimport 

mysqlpump 

mysqlsh 

mysqlshow 

mysqlslap 

 

* uses the following environment variables 

 

MYSQL_UNIX_PORT   - default Unix socket file; used for connections to localhost 

MYSQL_TCP_PORT    - default port number; used for TCP/IP connections 

MYSQL_PWD         - default password (insecure to use) 

MYSQL_DEBUG Debug - trace options when debugging 

TMPDIR            - directory where temporary tables and files are created 

 

full list of environment variables: 

 

administrative and utility programs: 

 

innochecksum 

myisam_ftdump 

myisamchk 

myisamlog 

myisampack 

mysql_config_editor 

mysqlbinlog 

mysqldumpslow 

 

development programs: 

 

mysql_config 

my_print_defaults 

resolve_stack_dump 

 

miscellaneous programs: 

 

lz4_decompress 

perror 

replace 

resolveip 

zlib_decompress 

 

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 

 

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