Re: FN-FORUM: mysql question - large text file
date posted 7th January 2004 12:13
Easier way (if the file is on the server) is:
use test;
create table foo(id integer, data longtext);
insert into foo values(1, load_file('/home/davidz/myfile'));
For the above to work you have to have:
- FILE privilege for the user logging into mysql
- the file has to be smaller than max_allowed_packet. To find out what
max_allowed_packet is use the following command:
show variables like '%allowed%';
- If it is too small, it is easy to increase it to any reasonable amount.
Cheers,
Dave.
On Wed, 2004-01-07 at 10:18, Dom wrote:
> On Wednesday 07 Jan 2004 4:20 am, Craig Tinson wrote:
> > anyone know off the top of their heads how to import a large (about 1Mb)
> > text file into a single field in a mysql table? it has various commas,
> > appostrophes and quotes etc in it...
>
> First I'd ask myself whether I really really wanted to do this
> (as per Joe's comment) and then I'd most likely knock up a
> small PHP script to open the file, suck it into a string ,
> and insert it into the table, not forgetting to use addslashes().
>
> --
> 5: When responding to a post, delete all information that is not
> strictly necessary. This includes the freelancers tag line and .sig
> files. Delete anything you're not specifically responding to.
>