?
Solved

How to extract data of certain tables using ssh

Posted on 2009-12-23
7
Medium Priority
?
248 Views
Last Modified: 2013-12-26
I know this code below will show the sql schema of the table and data of all that is in the database.

mysqldump -u<dbusername> -p<dbpassword> <databasename>  --tables

But how can i only show the sql database schema of certain tables only and only the first line of data in those certain tables?

example:
table1, table2, table4,..etc
0
Comment
Question by:Sam Cohen
  • 4
  • 3
7 Comments
 
LVL 14

Expert Comment

by:jb1dev
ID: 26116326
You can create a sql script like this:

-- script.sql ---
desc addresses;
select * from addresses limit 1;

-- end --

II use table "addresses" you can use any table you like.

Then do:
mysql -u user -ppass dbname < script.sql

0
 
LVL 14

Accepted Solution

by:
jb1dev earned 1500 total points
ID: 26116339
Or if you prefer it all in one .sh script you can inline the sql liek this.

#!/bin/sh

mysql -u test -ptest test <<EOF
desc addresses;
select * from addresses limit 1;
EOF

Open in new window

0
 
LVL 8

Author Comment

by:Sam Cohen
ID: 26116376
Im using terminal.

So willthis give me a dump of the sql schema?
0
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 
LVL 8

Author Comment

by:Sam Cohen
ID: 26116412
so you are saying to run this from my command line:

#!/bin/sh

mysql -u <username> -p<pass> databasename <<EOF
desc table1;
select * from table1 limit 1;
EOF
 <<EOF
desc table2;
select * from table2 limit 1;
EOF
 <<EOF
desc table4;
select * from table1 limit 1;
EOF
 <<EOF
desc table4;
select * from table1 limit 1;
EOF
0
 
LVL 8

Author Comment

by:Sam Cohen
ID: 26116416
I mean:
#!/bin/sh

mysql -u <username> -p<pass> databasename <<EOF
desc table1;
select * from table1 limit 1;
EOF
 <<EOF
desc table2;
select * from table2 limit 1;
EOF
 <<EOF
desc table4;
select * from table4 limit 1;
EOF
0
 
LVL 8

Author Closing Comment

by:Sam Cohen
ID: 31669631
Wish could have had complete answer.
0
 
LVL 14

Expert Comment

by:jb1dev
ID: 26121626
#!/bin/sh

mysql -u <username> -p<pass> databasename <<EOF
desc table1;
select * from table1 limit 1;
desc table2;
select * from table2 limit 1;
desc table4;
select * from table1 limit 1;
desc table4;
select * from table1 limit 1;
EOF

0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
Utilizing an array to gracefully append to a list of EmailAddresses
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question