Solved

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

Posted on 2004-10-08
2
551 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
ID: 12265166
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
ID: 12267502
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

A lot of articles have been written on splitting mysqldump and grabbing the required tables. A long while back, when Shlomi (http://code.openark.org/blog/mysql/on-restoring-a-single-table-from-mysqldump) had suggested a “sed” way, I actually shell …
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

816 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