copy output from mysql console
Posted by: terraDon (---.hsd1.mn.comcast.net)
Date: July 20, 2011 04:55PM

I have discovered that I can copy text from a text editor, place it on the windows clipboard and then in the console right click and choose paste. That makes it much easier to develop queries than typing directly into the console.
Is there an easy way to copy the output and paste into a text editor?

For example, I run mysql> SHOW CREATE TABLE mytable;
On screen, is everything needed to paste into a CREATE TABLE command to recreate the table structure. It could be a time saver, but not if I have to retype it.

Options: ReplyQuote
Re: copy output from mysql console
Posted by: stevenmartin99 (---.b-ras1.srl.dublin.eircom.net)
Date: July 20, 2011 04:58PM

You dont need to be using the console at all smiling smiley

use phpmadmin.. you can run sql queries from here .


if you need to copy on the console - right click the top window bar and press edit> mark

mark the text you need

right click the top bar>edit>copy


OR

a much easier way is to save the output to a file

at the end of your query write

>> file.txt




this will send the output into a file named file.txt in the mysql folder

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: copy output from mysql console
Posted by: terraDon (---.hsd1.mn.comcast.net)
Date: July 20, 2011 06:24PM

Thanks Steven,

Mark and then copy is exactly what I spent hours trying to figure out.

I use phpmyadmin for some things, but after too many dumps and imports that have the error only at the end of the .sql file with no other idication that there was a problem, I'm hesitant to use it.

I get a syntax error when I try to have the output sent to a file.

mysql> show create_table my_contacts >> file.txt;
or
mysql> show create_table my_contacts; >> file.txt

What have I misunderstood?

Thanks again!
Don

Options: ReplyQuote
Re: copy output from mysql console
Posted by: stevenmartin99 (---.b-ras1.srl.dublin.eircom.net)
Date: July 20, 2011 06:33PM

oh i didnt realise your useing the actual mysql console

i thought you were using

mysql.exe query >>file.txt



to send output to a file from the mysql> console use

INTO OUTFILE 'filename.txt'

--------------------------------------------------


you can also import sql queries on the mysql> console using the command


mysql> source filename.txt

or

mysql> \. filename.txt


queries (1 per line) will be processed

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: copy output from mysql console
Posted by: terraDon (---.hsd1.mn.comcast.net)
Date: July 20, 2011 09:53PM

Thanks for the detailed explanations. Rather hesitantly, I decided to try entering and then running commands from phpmyadmin. OK...I'm sold. I was afraid that I wouldn't get the same feedback from MySQL. You do. I want to write and try writing my own commands so I fully understand what is happening.
Thanks for your patience.
Don

Options: ReplyQuote
Re: copy output from mysql console
Posted by: yfastud (Moderator)
Date: July 21, 2011 12:15AM

If using it a lot, you should write a small php script to take care of it instead manually copy and paste too many times winking smiley

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote
Re: copy output from mysql console
Posted by: bethabernathy (70.134.93.---)
Date: July 23, 2011 07:13PM

New email today is: bethaber@gmail.com:

Hi There - I tried to run a sql query using the edit and selecting the field "CompanyName" from the mysql database in phpadmin and it returns all rows rather than the one I am searching for which starts as "Dem*"

I cut and pasted a sql query from an access database that contain the exact data from the mysql database as follows:

SELECT [table 1].CompanyName
FROM [table 1]
WHERE ((([table 1].CompanyName) Like "*Deme*"winking smiley);

This returns an error in the sql query in MYSQL that says:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[table 1].CompanyName FROM [table 1] WHERE ((([table 1].CompanyName) Like "*De' at line 1


I would like to use the edit and narrow my search, but I can't figure out how to do this. Any suggestions would be appreciated. Thanks so much. -Beth

Options: ReplyQuote
Re: copy output from mysql console
Posted by: stevenmartin99 (---.b-ras1.srl.dublin.eircom.net)
Date: July 23, 2011 07:14PM

you cant use ACCESS code in MYSQL


you will need to use the MYSQL keywords WHERE and LIKE to do this

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: copy output from mysql console
Posted by: bethabernathy (70.134.93.---)
Date: July 23, 2011 07:20PM

Hi There - Is there a way to use the edit tab and narrow the search qry? Thanks so much.

Options: ReplyQuote
Re: copy output from mysql console
Posted by: bethabernathy (70.134.93.---)
Date: July 23, 2011 08:55PM

O.K. I got it to work:

SELECT CompanyName FROM `table 1` WHERE CompanyName LIKE 'Dem%'

Options: ReplyQuote
Re: copy output from mysql console
Posted by: bethabernathy (70.134.93.---)
Date: July 23, 2011 11:04PM

Now I am just trying to add in fields without data listed?

Options: ReplyQuote
Re: copy output from mysql console
Posted by: terraDon (---.hsd1.mn.comcast.net)
Date: July 24, 2011 09:29PM

ALTER TABLE my_table_name
ADD COLUMN column_name VARCHAR(30)

That adds a column to your table that can hold up to 30 characters.
It will add it after the currunt last column.

Options: ReplyQuote


Sorry, only registered users may post in this forum.