If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > how to replace contents of one column in a mysql db from a text file

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-16-11, 15:19
inosent inosent is offline
Registered User
 
Join Date: Apr 2011
Posts: 3
how to replace contents of one column in a mysql db from a text file

hi

i am using phpMyAdmin - 2.11.11.3 and MySQL client version: 4.1.22 using the web interface of phpMyAdmin

i have a mysql db table with a column called added_on where the data in it was wiped out. i have the data for that column in a text file but i dont know how to place it in the mysql db online

i wish it were as easy as copying and pasting into excel for example, but this is a little different

i have been trying to use the import command at the web page, but the data is not getting into the column

i realize this is a very basic question, but i have no idea how to get the data back into that column
Reply With Quote
  #2 (permalink)  
Old 04-16-11, 15:53
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
please do a SHOW CREATE TABLE for your table

also, what fields are available in the text file for matching up with the table?

you should import the text file into its own table, and do a SHOW CREATE TABLE on that one too

meanwhile, i've asked the moderators to move this thread to the mysql forum
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 04-16-11, 16:58
inosent inosent is offline
Registered User
 
Join Date: Apr 2011
Posts: 3
This is the code when i created the contents of the affected table to a copy so as i figured out how to restore the added_on column i wouldnt mess up the original.



Code:
CREATE TABLE `accessmy_clone`.`files_to_notes_bu_rev` (
`notes_id` bigint( 20 ) NOT NULL default '0',
`files_id` int( 11 ) default NULL ,
`added_by` bigint( 20 ) default NULL ,
`added_on` int( 11 ) default NULL ,
`notes` mediumtext,
`notes_category` int( 1 ) NOT NULL default '0',
PRIMARY KEY ( `notes_id` )
) ENGINE = MYISAM DEFAULT CHARSET = latin1;

INSERT INTO `accessmy_clone`.`files_to_notes_bu_rev`
SELECT *
FROM `accessmy_clone`.`files_to_notes` ;
as far as the file that has the data, it is one column saved in a text file, with 119,000 rows, the exact same number as the table noted above. it is just a raw txt file. if it needs to be another sort of file i can convert it to suit

thanks for the reply
Reply With Quote
  #4 (permalink)  
Old 04-16-11, 18:48
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
um... your text file has only one column?

i'm afraid you're going to have to write some application code to do the update

you won't be able to process the updates with only sql
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 04-17-11, 05:44
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Moved thread to MySQL forum.
__________________
Mike
Reply With Quote
  #6 (permalink)  
Old 04-17-11, 14:19
inosent inosent is offline
Registered User
 
Join Date: Apr 2011
Posts: 3
ok, so let's say i export all the data with all the columns, then replace the column with the missing data with the data it needs to have, and save it as a csv file, is there a way to import that into a new table or an existing one?
Reply With Quote
  #7 (permalink)  
Old 04-17-11, 14:42
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by inosent View Post
ok, so let's say i ...
yes, that will work, you would import the csv using the LOAD DATA INFILE command
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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