Find the answer to your Linux question:
Results 1 to 7 of 7
Maybe I got this totally wrong but I believe you can put MP3, video etc in a blob column. How do I insert it? I believe mp3.com uses mysql to ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux User Allblack's Avatar
    Join Date
    May 2003
    Location
    Godzone
    Posts
    416

    inserting into BLOB column type


    Maybe I got this totally wrong but I believe you can put MP3, video etc in a blob column.

    How do I insert it? I believe mp3.com uses mysql to store there mp3 files.

    Can anyone help me?
    I am on a journey to mastering Linux and I got a bloody long way to go!!!

  2. #2
    Linux Engineer
    Join Date
    Jan 2003
    Location
    Lebanon, pa
    Posts
    994
    Same way you would text data:

    INSERT into <table> (blob_col) values ('data here');

    With something like perl you could just do this:

    open(FILE, "/path/to/file");
    $blob=<FILE>;
    $query='insert into blob_table (blob) values (?);';
    $sth=$db -> prepare($query);
    $sth -> execute($blob);

  3. #3
    Linux User Allblack's Avatar
    Join Date
    May 2003
    Location
    Godzone
    Posts
    416
    Thanks Genlee

    Is there a way I can specify a path into the Insert command?
    Something like Insert into mytable mp3column values(\path\to\mp3\)?

    Let's say that I have all my files on the same box but in a different directory. What is the best way of doing this without using script
    I am on a journey to mastering Linux and I got a bloody long way to go!!!

  4. #4
    Linux Engineer
    Join Date
    Jan 2003
    Location
    Lebanon, pa
    Posts
    994
    INSERT INTO blob_tabl (some_col) values(load_file('/path/to/file')); ;

  5. #5
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    In that case, the easiest way to automate it is probably to run this command:
    Code:
    &#40;for file in /path/to/files/*; do echo 'INSERT INTO blob_tabl &#40;some_col&#41; values &#40;load_file&#40;'\'"$file"\''&#41;&#41;;'; done&#41; | mysql -D some_db -u some_user -p

  6. #6
    Linux User Allblack's Avatar
    Join Date
    May 2003
    Location
    Godzone
    Posts
    416
    Thanks guys, I will give that a go. Is there a special way to extract it as well? Lets say that I want to extract it to an other folder. Can I do this with a select statement?

    Cheers
    I am on a journey to mastering Linux and I got a bloody long way to go!!!

  7. #7
    Linux Engineer
    Join Date
    Apr 2003
    Location
    Sweden
    Posts
    796
    Use my program DBloader (engine) on my page (the link below) to load info of music or ftproot structures (or any other structure) in to mysql,mssql,postregsql..

    you can easily modify it to load the mp3-file like a blob instead, if you need any help with that just let me know. Or if you have questions about the program.
    Regards

    Andutt

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •