Solved

How to upload data to MySql databse (phpMyAdmin, Yahoo store host)

Posted on 2004-10-08
2
536 Views
Last Modified: 2008-03-06
How do I upload data to my MySql database? Using phpMyAdmin, I see how to do a dump (getting data out) but not how to get data in.

I've tried using the feature "insert data from a textfile into a table", which allows me to browse to a local file, but the filename arrives blank into the SQL-query and I get the following statement, with an error:  

LOAD DATA LOCAL INFILE '' INTO TABLE `Customer` FIELDS TERMINATED BY ';' ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\r\n'

MySQL said:
File '' not found (Errcode: 2)

I have MySQL installed locally.  Can I maintain my databases from here?  

My goal is to sync our local customer and product info with my on-line tables.

Alex
0
Comment
Question by:idolcemia
2 Comments
 
LVL 26

Accepted Solution

by:
ushastry earned 500 total points
Comment Utility
Hi,

( I have taken below text from a forum)

I think it has to do with PHP running in safe mode, or it could be that the temp directory has not been defined in the ini file on the server.
In PHPMyAdmin you have to upload a file to import into MySQL. If PHP is installed in safe mode, then this is not permitted (it is not permitted to access files in the temp directory). Try the function phpinfo() and you'll see an overview of PHP settings and whether or not a temp directory has been set.

Try to contact your serveradministrator and ask if they can install PHP without the save mode. I had the same thing once.

>>I have MySQL installed locally.  Can I maintain my databases from here?  

Ofcource  yes..

For security reasons, when reading text files located on the server, the files must either reside in the database directory or be readable by all. Also, to use LOAD DATA INFILE on server files, you must have the FILE privilege. See section 5.5.3 Privileges Provided by MySQL.



To read the comma-delimited file back in, the correct statement would be:

mysql> LOAD DATA INFILE 'data.txt' INTO TABLE Customer FIELDS TERMINATED BY ',';

To read the tab-delimited file back in, the correct statement would be:

mysql> LOAD DATA INFILE 'data.txt' INTO TABLE Customer FIELDS TERMINATED BY '\t';


If you specify a FIELDS clause, each of its subclauses (TERMINATED BY, [OPTIONALLY] ENCLOSED BY, and ESCAPED BY) is also optional, except that you must specify at least one of them.

If you don't specify a FIELDS clause, the defaults are the same as if you had written this:

FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\'

If you don't specify a LINES clause, the default is the same as if you had written this:

LINES TERMINATED BY '\n' STARTING BY ''


You can check these if you need more info on this..

http://dev.mysql.com/doc/mysql/en/Loading_tables.html
http://dev.mysql.com/doc/mysql/en/LOAD_DATA.html


Hope This Helps!






0
 

Author Comment

by:idolcemia
Comment Utility
I ran phpinfo() and discovered the following:

safe_mode=Off
upload_tmp_dir=tmp, which didn't exist so I created it.

And now it works!  It uploads my local file to /tmp, reads it into the table, and deleted it (apparently, because /tmp is empty when the operation's through.)

Thanks a lot!

-Alex
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Creating and Managing Databases with phpMyAdmin in cPanel.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now