Mysql examples: Difference between revisions

From lippmann wiki
Jump to navigation Jump to search
No edit summary
Line 14: Line 14:
Directly from the mysql cli, or when piped to the mysql client:
Directly from the mysql cli, or when piped to the mysql client:
  SELECT * FROM employees INTO OUTFILE '/tmp/employees.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'
  SELECT * FROM employees INTO OUTFILE '/tmp/employees.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'
With echo in a single line:


  echo SELECT \* FROM employees  INTO OUTFILE  \'/tmp/employees.csv\' FIELDS TERMINATED BY \',\' ENCLOSED BY \'\"\' LINES TERMINATED BY \'\\n\' | mysql -u root -p company
  echo SELECT \* FROM employees  INTO OUTFILE  \'/tmp/employees.csv\' FIELDS TERMINATED BY \',\' ENCLOSED BY \'\"\' LINES TERMINATED BY \'\\n\' | mysql -u root -p company

Revision as of 17:30, 7 June 2015

add a column to a table

ALTER TABLE exports ADD level VARCHAR(20);

rename or change a colume data type

ALTER TABLE exports CHANGE hostname name  INT

insert some values

INSERT INTO exports (hostname, export) VALUES('fuego', 'sec=sys,rw' )

output to csv

Directly from the mysql cli, or when piped to the mysql client:

SELECT * FROM employees INTO OUTFILE '/tmp/employees.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'

With echo in a single line:

echo SELECT \* FROM employees   INTO OUTFILE  \'/tmp/employees.csv\' FIELDS TERMINATED BY \',\' ENCLOSED BY \'\"\' LINES TERMINATED BY \'\\n\' | mysql -u root -p company