SQL Dump in DB importieren

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • SQL Dump in DB importieren

    Hallo!

    Ich habe bei phpmyadmin das übliche Problem, dass die 30 sec. beim importieren einer 1,6 MB großen Datei überschritten werden.
    habe mir gedacht, dass es doch möglich sein muss ein Script zu coden mit dem ich einen SQL Dump der bereits auf dem Server bereitliegt schneller in die Datenbank bekomme.
    Ist sowas möglich? wenn ja - wie?

    Gruss
    Eric

  • #2
    hth

    Code:
    mysql --user=<username> --password=<password> --database=<database> < sqlfile.sql
    Code:
    [root@.... ]# mysql --help
    mysql  Ver 11.18 Distrib 3.23.58, for redhat-linux-gnu (i386)
    Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
    This software comes with ABSOLUTELY NO WARRANTY. This is free software,
    and you are welcome to modify and redistribute it under the GPL license
    
    Usage: mysql [OPTIONS] [database]
    
      -?, --help            Display this help and exit.
      -A, --no-auto-rehash  No automatic rehashing. One has to use 'rehash' to
                            get table and field completion. This gives a quicker
                            start of mysql and disables rehashing on reconnect.
      -B, --batch           Print results with a tab as separator, each row on
                            a new line. Doesn't use history file.
      --character-sets-dir=...
                            Directory where character sets are located.
      -C, --compress        Use compression in server/client protocol.
      -D, --database=..     Database to use.
      --default-character-set=...
                            Set the default character set.
      -e, --execute=...     Execute command and quit. (Output like with --batch)
      -E, --vertical        Print the output of a query (rows) vertically.
      -f, --force           Continue even if we get an sql error.
      -g, --no-named-commands
                            Named commands are disabled. Use \* form only, or
                            use named commands only in the beginning of a line
                            ending with a semicolon (;) Since version 10.9 the
                            client now starts with this option ENABLED by
                            default! Disable with '-G'. Long format commands
                            still work from the first line.
      -G, --enable-named-commands
                            Named commands are enabled. Opposite to -g.
      -i, --ignore-spaces   Ignore spaces after function names.
      -h, --host=...        Connect to host.
      -H, --html            Produce HTML output.
      --local-infile=[1|0]  Enable/disable LOAD DATA LOCAL INFILE
      -L, --skip-line-numbers
                            Don't write line number for errors.
      --no-pager            Disable pager and print to stdout. See interactive
                            help (\h) also.
      --no-tee              Disable outfile. See interactive help (\h) also.
      -n, --unbuffered      Flush buffer after each query.
      -N, --skip-column-names
                            Don't write column names in results.
      -O, --set-variable var=option
                            Give a variable an value. --help lists variables.
      -o, --one-database    Only update the default database. This is useful
                            for skipping updates to other database in the update
                            log.
      --pager[=...]         Pager to use to display results. If you don't supply
                            an option the default pager is taken from your ENV
                            variable PAGER ().
                            Valid pagers are less, more, cat [> filename], etc.
                            See interactive help (\h) also. This option does
                            not work in batch mode.
      -p[password], --password[=...]
                            Password to use when connecting to server
                            If password is not given it's asked from the tty.
    
      -P, --port=...        Port number to use for connection.
      -q, --quick           Don't cache result, print it row by row. This may
                            slow down the server if the output is suspended.
                            Doesn't use history file.
      -r, --raw             Write fields without conversion. Used with --batch
      -s, --silent          Be more silent.
      -S  --socket=...      Socket file to use for connection.
      -t, --table           Output in table format.
      -T, --debug-info      Print some debug info at exit.
      --tee=...             Append everything into outfile. See interactive help
                            (\h) also. Does not work in batch mode.
      -u, --user=#          User for login if not current user.
      -U, --safe-updates[=#], --i-am-a-dummy[=#]
                            Only allow UPDATE and DELETE that uses keys.
      -v, --verbose         Write more. (-v -v -v gives the table output format)
      -V, --version         Output version information and exit.
      -w, --wait            Wait and retry if connection is down.
    
    Default options are read from the following files in the given order:
    /etc/my.cnf /var/lib/mysql/my.cnf ~/.my.cnf 
    The following groups are read: mysql client
    The following options may be given as the first argument:
    --print-defaults        Print the program argument list and exit
    --no-defaults           Don't read default options from any options file
    --defaults-file=#       Only read default options from the given file #
    --defaults-extra-file=# Read this file after the global files are read
    
    Possible variables for option --set-variable (-O) are:
    connect_timeout       current value: 0
    max_allowed_packet    current value: 16777216
    net_buffer_length     current value: 16384
    select_limit          current value: 1000
    max_join_size         current value: 1000000
    INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


    Kommentar


    • #3
      Wie soll ich das verstehen?
      Was das denn?

      Sollte vielleicht dazu sagen, dass ich keinen root Zugriff auf dem Server habe. Auch kein SSH Zugang möglich.

      Kommentar


      • #4
        deswegen habe ich die die help auch gepostet..
        INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


        Kommentar


        • #5
          Hmm... sorry, verstehe gerade nur Bahnhof
          Kann jemand, dem das mehr sagt, evtl. 'n paar Worte dazu verlieren, wie ich das anwende ?

          Kommentar


          • #6
            Also ich habe das eigentlich soweit verstanden und bin auch glücklich, dass du es gepostet hast, da ich soetwas schon länger gesucht habe

            Einen SQL-Dump für die lokale DB zu importieren geht problemlos, allerdings kann ich nicht zu meinem entfernten MySQL-Server connecten und einen Dump reinladen, da er keine Verbindung aufbauen kann. Ich vermute mal, dass es daran liegt, dass der Server dies nicht zuläßt (denn die Verbindungsdaten stimmten). Also frag' ich mich ob es evt. noch eine andere Lösung dafür gibt oder ob es für dieses "Programm" eine noch umfassendere Dokumentation gibt?

            regards
            Smiller
            Zuletzt geändert von Smiller; 06.03.2004, 23:20.

            Kommentar


            • #7
              hmm?
              wie sieht denn dein script aus und wie wendst du es an?
              will das auch können

              Kommentar


              • #8
                Also lokal, ganz einfach... (WinXP)

                Start -> Ausführen -> "cmd"

                Dort gibst du dann die oben genannte Befehlskette mit deinen Daten an. Das war's schon

                Kommentar


                • #9
                  Original geschrieben von Smiller
                  Also ich habe das eigentlich soweit verstanden und bin auch glücklich, dass du es gepostet hast, da ich soetwas schon länger gesucht habe


                  Original geschrieben von Smiller
                  [...] Ich vermute mal, dass es daran liegt, dass der Server dies nicht zuläßt (denn die Verbindungsdaten stimmten). [...]
                  ja. die meisten hoster unterbinden eine externen zugriff.

                  Original geschrieben von Smiller
                  [...] Also frag' ich mich ob es evt. noch eine andere Lösung dafür gibt [...]
                  sicher .. ;-)

                  datei auf den server laden und dort ausführen.

                  dies kann helfen:
                  system() / exec() -> www.php.net

                  Original geschrieben von Smiller
                  [...] oder ob es für dieses "Programm" eine noch umfassendere Dokumentation gibt?
                  naja. aber viel mehr infos stehen da auch nicht drin...
                  Code:
                  [root@.... ]# man mysql | cat
                  mysql(1)                        MySQL database                        mysql(1)
                  
                  
                  
                  NAME
                         mysql  -  text-based client for mysqld, a SQL-based relational database
                         daemon
                  
                  SYNOPSIS
                         mysql [-B|--batch] [-#|--debug= logfile] [-T|--debug-info]  [-e|--exec=
                         command]     [-f|--force]     [-?|--help]     [-h|--host=     hostname]
                         [-n|--unbuffered]  [-p[pwd]]   [--password=[pwd]]   [-P|--port=   pnum]
                         [-q|--quick]  [-r|--raw]  [-s|--silent] [-S|--socket= snum] [-u|--user=
                         uname] [-v|--verbose] [-V|--version] [-w|--wait]
                  
                  DESCRIPTION
                         The mysql program provides a curses-based interface  to  the  SQL-based
                         database server daemon, mysqld(1).  Full fuller documentation, refer to
                         the HTML documents installed with the package.
                  
                  OPTIONS
                         -B|--batch
                                Print results with a tab as separator, each row on a new line.
                  
                         -#|--debug=logfile
                                Employ the specified debug log.
                  
                         -T|--debug-info
                                Print debug information upon exiting.
                  
                         -e | --exec=command
                                Execute the specified command and quit (--batch is implicit).
                  
                         -f|--force
                                Continue even if the face of a SQL error.
                  
                         -?|--help
                                Display a help message and exit.
                  
                         -h|--host=hostname
                                Connect to the specified host.
                  
                         -n|--unbuffered
                                Flush the buffer after each query.
                  
                         -p|--password[=pwd]
                                Employ the specified password when connecting  to  the  database
                                server.   If  a  password  is not supplied, it will be requested
                                interactively.
                  
                         -P|--port=pnum
                                Employ the specified port number for connecting to the  database
                                server.
                  
                         -q|--quick
                                Do  not  cache  the  result; print it row by row.  This may slow
                                down the server if the output is suspended.
                  
                         -r|--raw
                                Write fields without conversion.  (used with --batch).
                  
                         -s|--silent
                                Silent mode: reduce the amount of output.
                  
                         -S|--socket=snum
                                Employ the specified socket file for connecting to the  database
                                server.
                  
                         -u|--user=uname
                                Employ the specified user name for logging in to the server.
                  
                         -v|--verbose
                                Verbose mode: write more Specifying this option twice produces a
                                tabular output format.
                  
                         -V|--version
                                Print the mysql version number and exit.
                  
                         -w|--wait
                                Wait and retry if the database server connection is down.
                  
                  FILES
                         /depot/bin/mysql      executable
                  
                         /depot/bin/mysqld     executable
                  
                         /depot/bin/safe_mysqld
                                               executable  shell  script  for  starting   mysqld
                                               safely
                  
                         /site/var/mysql/data  location of database files
                  
                  EXAMPLE
                         You can also read a backup dump file back into MySQL with:
                  
                         mysql  database < backup-file.sql
                  
                  SEE ALSO
                         isamchk  (1),  isamlog  (1),  mysqlaccess (1), mysqladmin (1), mysqlbug
                         (1), mysqld (1), mysqldump (1), mysqlshow (1), msql2mysql  (1),  perror
                         (1), replace (1), safe_mysqld (1), which1 (1), zap (1),
                  
                  AUTHOR
                         Ver  6.3, distribution 3.20.20 Michael (Monty) Widenius (monty@tcx.se),
                         TCX Datakonsult AB ([url]http://www.tcx.se[/url]).  This software  comes  with  no
                         warranty.  Manual page by R. P. C. Rodgers, Lister Hill National Center
                         for  Biomedical  Communication,  U.S.  National  Library  of   Medicine
                         (rodgers@nlm.nih.gov).
                  
                  
                  
                  MySQL 3.23                     19 December 2000                       mysql(1)
                  INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


                  Kommentar


                  • #10
                    Ich danke dir sehr für die ganzen Infos.

                    So habe mich jetzt etwas informiert und wollte jetzt vorher anfragen, ob dies so richtig wäre, denn ich hab keine Lust den Server zu crashen

                    PHP-Code:
                    exec("mysql --host=<mysql-host> --user=<username> --password=<password> --database=<database> < sqlfile.sql"); 
                    Bekomme ich eventuell probleme mit dem PHP-Timeout, oder läuft das davon seperat? (die Datei ist maximal 8 MB groß)

                    regards
                    Smiller

                    Edit: [COLOR=red]Nächstes großes Problem [/COLOR]
                    Warning: exec,passthru,proc_open,system,popen() has been disabled for security reasons

                    Damit hat sich das wohl erledigt, oder?
                    Zuletzt geändert von Smiller; 07.03.2004, 10:22.

                    Kommentar


                    • #11
                      sprich mal mit deinem hoster über alternativen.
                      INFO: Erst suchen, dann posten![color=red] | [/color]MANUAL(s): PHP | MySQL | HTML/JS/CSS[color=red] | [/color]NICE: GNOME Do | TESTS: Gästebuch[color=red] | [/color]IM: Jabber.org |


                      Kommentar

                      Lädt...
                      X