Avatar billede fredand Forsker
06. september 2007 - 21:10 Der er 10 kommentarer og
1 løsning

How to import a dump to MySql with ANT?

Hello!

If I have a dump from a database created like:
mysqldump -u root -pmy_pass --database howto > howto.sql

How do I import it to a MySql database?
I have tried:
    mysqlimport -u root -pmy_pass howto howto.sql
    and
    mysqlimport --local howto howto.sql

But it does not looks like it work.
Perhaps mysqlimport only imports comma separated files?

If you have any ideas how to put it into a ant-target as well it would be great also!

Best regards
Fredrik
Avatar billede pidgeot Nybegynder
06. september 2007 - 21:13 #1
Have you considered piping it into the regular mysql client executable?

mysql -u root -pmy_pass howto < howto.sql
Avatar billede arne_v Ekspert
06. september 2007 - 21:18 #2
proev:

mysql -u root -pmy_pass < howto.sql
Avatar billede fredand Forsker
07. september 2007 - 10:38 #3
I will try it at home!
Exciting!!

Btw is mysqlimport only for comma separated files? Then I guess the mapping is one file for each table?

Best regards
Fredrik
Avatar billede arne_v Ekspert
08. september 2007 - 02:20 #4
Yes (with flexibility for delimiters though).
Avatar billede fredand Forsker
11. september 2007 - 22:33 #5
Hello Arne!

I tried "mysql -u root -pmy_pass howto < D:\how
to5.sql" from command line.

But when I try it like this from ANT:
    <target description="Import the database howto" name="import">
        <exec executable="mysql">
          <arg line="-u root -pmy_pass howto < D:\howto5.sql"/>
        </exec>
    </target>

I get:
D:\ant\build.xml:56: The value of attribute
"line" associated with an element type "arg" must not contain the '<' character.

Do you have any idea how to solve this?

I have also tried:
<arg line="-u root -pmy_pass howto --local-infile D:\howto5.sql"/>
<arg line="-u root -pmy_pass howto &lt; D:\howto5.sql"/>

Tricky.

Best regards
Fredrik
Avatar billede arne_v Ekspert
11. september 2007 - 22:39 #6
Try:

cmd /c mysql ... < ...
Avatar billede pidgeot Nybegynder
11. september 2007 - 22:42 #7
I just checked the ant documentation, and according to that, it should be like this:

        <exec executable="mysql" input="D:\howto5.sql">
          <arg line="-u root -pmy_pass howto"/>
        </exec>

You need Ant 1.6 or later. (see http://ant.apache.org/manual/CoreTasks/exec.html)
Avatar billede arne_v Ekspert
11. september 2007 - 22:49 #8
Or try specify the file as input attribute to the exec tag.
Avatar billede fredand Forsker
11. september 2007 - 22:53 #9
Hello guys!
I tried the cmd version as well but I got the same error.
But the:
        <exec executable="mysql" input="D:\howto5.sql">
          <arg line="-u root -pmy_pass howto"/>
        </exec>
...really did the trick!

Please bothof you give answers so I an reward you!
Again, thanks alot!!!
Best regards
Fredrik
Avatar billede pidgeot Nybegynder
11. september 2007 - 23:00 #10
You're welcome :)
Avatar billede arne_v Ekspert
12. september 2007 - 03:16 #11
Give the points to pidgeot - he was first with the answer.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Computerworld tilbyder specialiserede kurser i database-management

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester