August 21, 2008

MySQL - Functions

>LOAD DATA LOCAL INFILE '/location/file' INTO TABLE table FIELDS TERMINATED BY '/n';
Uploading data into tables from a file.

>
DELETE FROM table
Delete all data from table

>
LOAD DATA LOCAL INFILE '/location/file' INTO TABLE table (column1);
Load data into a table from a file into particular columns.

>
LOAD DATA LOCAL INFILE '/location/file' INTO TABLE table (column1) SET (column2) = 'data';
Add a value to the column that is not in the source file. Ensure the '( )' are around the column1 name.

>
SELECT version();
Determine the version on MySQL you are running.

>
SELECT now();
Determine the date and time.

>
MYSQLDUMP -u username -p databasename > filename.sql
Backup the entire database from the command prompt.

>
DELETE FROM table where Field = 'value';
To delete a row from the database.

>
Select * From table WHERE value NOT IN (SELECT value FROM table Union SELECT value FROM table);
Query data from two separate tables where it does not exist in the master table.

>
SELECT DISTINCT field FROM table INTO OUTFILE '/location/filename';
Directs the output to a file.

>
CREATE TABLE Name Select * from Orginal_Table;
Create a table structure from another table.

>
Select a.IP, b.nessus as nessus, c.patchlink as patchlink, d.nmap as nmap from JASON2_Inv as a left join Scan_Nessus_Inv as b on a.IP = b.IP left join Scan_Patchlink_Inv as c on a.IP = c.IP left join Scan_NMAP_Inv as d on a.IP = d.IP;
This is an example of a left join with four tables.