IT Community - Software Programming, Web Development and Technical Support

How do we import or export data in MySql

This is a discussion on How do we import or export data in MySql within the Database Support forums, part of the Web Development category; hi, How do we import or export data in MySql from outside sources? For example if i have DATA in ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > Database Support

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 08-14-2007, 01:37 AM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,162
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default How do we import or export data in MySql

hi,
How do we import or export data in MySql from outside sources?

For example if i have DATA in XML file, here i want to import to DB with MySql server. How can i do that?
__________________
With,
J. Jeyaseelan

Everything Possible
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-14-2007, 03:14 AM
write2ashokkumar write2ashokkumar is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 85
write2ashokkumar is on a distinguished road
Default Re: How do we import or export data in MySql

Hi...

We can export the mysql table data to text file, and also possible to import from the text file to table.

Example:

Consider the table name is sample.

Query to Export data to text file :


SELECT id,name INTO OUTFILE '/home/www/htdocs/test/backup_test.xls' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' from sample;

Query to Import data from text file :


LOAD DATA INFILE '/home/www/htdocs/test/backup_test.txt' INTO TABLE sample FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';


Regards,
S.Ashokkumar
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-14-2007, 03:23 AM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,162
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default Re: How do we import or export data in MySql

Hi ashok,
thanks for you reply. I hope that it would help me lot. I have small doubt that is it possible to import or export from XML file?

Becaz i have used openxml in SQL server to get XML tag values. is there any chance to use like this?
__________________
With,
J. Jeyaseelan

Everything Possible
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-14-2007, 03:58 AM
Murali Murali is offline
D-Web Master
 
Join Date: Feb 2007
Location: India-Chennai.
Posts: 386
Murali is on a distinguished road
Send a message via AIM to Murali
Default Re: How do we import or export data in MySql

Quote:
Originally Posted by Jeyaseelansarc View Post
hi,
How do we import or export data in MySql from outside sources?

For example if i have DATA in XML file, here i want to import to DB with MySql server. How can i do that?

Refer this.
__________________
-Murali..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 08-14-2007, 04:27 AM
write2ashokkumar write2ashokkumar is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 85
write2ashokkumar is on a distinguished road
Default Re: How do we import or export data in MySql

hi...

We can export the table data as XML file.

Command to export table data as XML file:

Syntax:


mysqldump -u root -p --xml <database_name> [table_name] > file_path;

Ex:

mysqldump -u root -p --xml test sample > /home/www/htdocs/test/bktest.xml;

Regards,
S.Ashokkumar.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 08-14-2007, 04:40 AM
Murali Murali is offline
D-Web Master
 
Join Date: Feb 2007
Location: India-Chennai.
Posts: 386
Murali is on a distinguished road
Send a message via AIM to Murali
Default Re: How do we import or export data in MySql

Quote:
Originally Posted by Jeyaseelansarc View Post
Hi ashok,
thanks for you reply. I hope that it would help me lot. I have small doubt that is it possible to import or export from XML file?

Becaz i have used openxml in SQL server to get XML tag values. is there any chance to use like this?
Refer this.
__________________
-Murali..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 08-14-2007, 04:42 AM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,162
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default Re: How do we import or export data in MySql

hi ashok,
this is ok for exporting data into XML file. is there any way to import XML data into DB?
__________________
With,
J. Jeyaseelan

Everything Possible
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 08-14-2007, 08:47 AM
Murali Murali is offline
D-Web Master
 
Join Date: Feb 2007
Location: India-Chennai.
Posts: 386
Murali is on a distinguished road
Send a message via AIM to Murali
Default Re: How do we import or export data in MySql

Hi Jeyaseelan,

Import XML Data to MYSQL Database.

Available only from MYSQL 5.1 which is in beta atpresent.
__________________
-Murali..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 08-17-2007, 07:25 AM
Murali Murali is offline
D-Web Master
 
Join Date: Feb 2007
Location: India-Chennai.
Posts: 386
Murali is on a distinguished road
Send a message via AIM to Murali
Default Re: How do we import or export data in MySql

Here is a sample for Export and Import XML in MYSQL

Code:
DROP TABLE IF EXISTS member;
CREATE TABLE member
(
	memberid 			INTEGER		PRIMARY KEY,
	member_fname 	VARCHAR(50),
	member_lname 	VARCHAR(50),
	member_email	VARCHAR(50)
);

INSERT INTO member VALUES (1,'Ram','Kumar','Hairam@hotmail.com');
INSERT INTO member VALUES (2,'Mukesh','Chandar','Mukesh@yahoo.co.in');
COMMIT;
Exporting table values to XML [Available in MYSQL5.0]

Code:
DB@Server# mysql -u <UserName> -p <Password> <DatabaseName> -X -e "SELECT * FROM members " > <File Destination Path .xml;
Check the file in the specified path
Code:

<?xml version="1.0"?>
<resultset statement="SELECT * FROM member">
  <row>
        <field name="memberid">1</field>
        <field name="member_fname">Ram</field>
        <field name="member_lname">Kumar</field>
        <field name="member_email">Hairam@hotmail.com</field>
  </row>

  <row>
        <field name="memberid">2</field>
        <field name="member_fname">Mukesh</field>
        <field name="member_lname">Chandar</field>
        <field name="member_email">Mukesh@yahoo.co.in</field>
  </row>
</resultset>

Import XML data to MYSQL Table[Available in MYSQL5.1]

Code:
mysql> CREATE TABLE members LIKE member; 
Query OK, 0 rows affected (0.00 sec)
Code:
DB@Server# mysql -u <UserName> -p <Password> <DatabaseName> -e "LOAD XML DATA INFILE '<XML FilePath' INTO TABLE members";
Check the Output
Code:

mysql> SELECT * FROM members;
+----------+--------------+--------------+--------------------+
| memberid | member_fname | member_lname | member_email       |
+----------+--------------+--------------+--------------------+
|        1 | Ram          | Kumar        | Hairam@hotmail.com |
|        2 | Mukesh       | Chandar      | Mukesh@yahoo.co.in |
+----------+--------------+--------------+--------------------+
2 rows in set (0.00 sec)


Hope it helps....
__________________
-Murali..
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
please tell me how to import excel data to sql server without datagrid oxygen C# Programming 2 12-16-2007 09:33 PM
Encrypting data in mysql eric PHP Programming 2 07-30-2007 06:08 AM
How can we import and export using BCP utility in SQL? oxygen Database Support 1 07-26-2007 04:33 AM
How to import MySQL Dump files? kingmaker Database Support 2 07-24-2007 04:47 AM
How to import foxpro tables into MySQL Databases priyan Database Support 2 05-21-2007 07:11 AM


All times are GMT -7. The time now is 06:55 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0