Monday, May 2, 2016

Reading from a file into MySQL

Basic load, there's lots more options for column delimiters, line delimiters, etc...

LOAD DATA INFILE '/tmp/mydata.txt' INTO TABLE Test;

Thursday, March 31, 2016

MySQL select on date range

Using date ranges in mysql...
 
select * from sale where date_begin between '2016-08-01' AND '2016-08-31';

Monday, March 28, 2016

Editing in hex mode in Vim

Native Vim doesn’t have a hex editing mode built in, however it is possible to edit a file in hex by converting the file back and forth using xxd. To do this, open your file in Vim and run :%!xxd. From here you can change the hex values and, when you’re done, run :%!xxd -r to convert back.

Tuesday, January 5, 2016

MySQL pager setting in ~/.my.cnf

I like setting the pager to less for the mysql client.  When I do it in my ~/.my.cnf file, thus...

[client]
pager=less

I get an error when running mysql dump...

mysqldump: unknown variable 'pager=less'

Turns out mysqldump also reads the [client] section of the file, as well as [mysqldump].  Using the following works...

[mysql]
pager=less

Tuesday, December 1, 2015

Autoformatting code in vim

To format a file in vim, gg=G (gg go to top of file, = format, G until end of file

More details here... http://stackoverflow.com/questions/11655383/vim-formatting-using-gg-g-with-xml

Monday, October 26, 2015

Export a CVS file from MySQL

To dump all the records from a table called "sale" into the file /tmp/sale.csv as a CSV file, use the following SQL query:

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

Showing all changed file buffers in vim

So, editing a rails project in vim + NERDTree, I often edit several files and then browser refresh to check my work.  If I forget to save a particular file, it's problematic to check all the buffers. In #vim, they told me about ':ls', which shows all buffers in that session, with a + before the ones that are unsaved.  Also, ':ls +' will just show the unsaved buffers.

Also, the % indicates the current buffer, the # indicates the buffer you get to with a ':e#'.

TIL...