Solved

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

Posted on 2004-10-08
2
558 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 26

Accepted Solution

by:
Umesh 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

737 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