MySQL

MySQL Command Line Examples

Command to log into remote host with username and password.

mysql --user=[username] --password=[password]--host=[computer]

Example:

mysql --user=root --password=mypassword--host=VMYSQL01

Show Databases

show databases;

Run script

mysql --user=root --password=mypassword --database=DB1< myscript.sql

mydumpsplitter - Extract tables from mysqldump

http://kedar.nitty-witty.com/blog/mydumpsplitter-extract-tables-from-mysql-dump-shell-script/

#!/bin/sh
# http://kedar.nitty-witty.com
#SPLIT DUMP FILE INTO INDIVIDUAL TABLE DUMPS
# Text color variables
txtund=$(tput sgr 0 1)    # Underline
txtbld=$(tput bold)       # Bold
txtred=$(tput setaf 1)    # Red
txtgrn=$(tput setaf 2)    # Green
txtylw=$(tput setaf 3)    # Yellow
txtblu=$(tput setaf 4)    # Blue
txtpur=$(tput setaf 5)    # Purple
txtcyn=$(tput setaf 6)    # Cyan
txtwht=$(tput setaf 7)    # White
txtrst=$(tput sgr0)       # Text reset
 
TARGET_DIR="."
DUMP_FILE=$1

Dump MySQL Table Information

This command will dump a table into a file without the data.

mysqldump --opt --user=[username] --password=[password] --no-data [database] [table] > [filename]
.
.

Dump the data in an XML format

mysqldump --opt --user=[username] --password=[password] --no-data --xml [database] [table] > [filename]
.
.

MySQL Update Example with INNER JOIN

UPDATE content_type_geshinode AS g
INNER join zztemp AS z ON z.nid = g.nid
SET g.field_object_type_value = z.field_object_type_value

Taxonmy - SQL INSERT Example

This example will explain how to write a simple SQL statement that will add items to the term_node table. To do this example, you will need access to your database by using a 3rd party program such as phpmadmin.