How to create a csv or excel file from a mysql query

So, every now and then you may want to have a table or some sql query as a csv or excel file to be able to do certain tasks like graphing etc.
Here a quick way to get that.

mysql -h Host -uUser -pPassword -D Database -e 'sql query;' | sed "s/'/\'/;s/\t/\",\"/g;s/^/\"/;s/$/\"/;s/\n//g" >MyFile.csv
Continue reading “How to create a csv or excel file from a mysql query”

How to check if a column with a particular name exists in a MySQL database

So,
Every now and then one runs into a situation where one has an idea of a column of a MySQL table.
A quick way to narrow down on the list of tables is to do a search using the part of the column name that one remembers.


SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME LIKE "%string%";

Where “string” is the string one is searching for.