IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Administration MySQL Discussion :

Sauvegarde efficace d'une base MySql sous Linux


Sujet :

Administration MySQL

  1. #1
    Membre chevronné
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2003
    Messages
    1 562
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Février 2003
    Messages : 1 562
    Points : 2 001
    Points
    2 001
    Par défaut [RESOLU] Sauvegarde efficace d'une base MySql sous Linux
    Bonjour,

    j'ai fait une recherche sur le forum MySql mais n'ai point trouvé ce qui m'intéresse.

    Etant programmeur Perl sous Linux, j'ai une base de données tournant sous MySql et dont j'aimerais, par un moyen rapide et fiable (bien entendu) pouvoir faire une sauvegarde régulière de la-dite base, c'est à dire sauvegarder à la fois la structure des tables de la bdd comme les enregistrements des tables.

    Bien sûr, pour que ce soit encore plus efficace, j'aimerais bien que la procédure soit toute aussi simple pour faire une restauration si le besoin s'en fait sentir.

    Je programmerais bien un script Perl créant un script SQL qui contiendrait toutes les manips à reproduire pour recréer la base mais bon, je me doute qu'il y a bien plus efficace (et fiable !).

    Pour info, je n'utilise aucune couche graphique ou autre truc à la PHP My Admin, je bosse en ligne de commande avec MySql.

  2. #2
    Invité
    Invité(e)
    Par défaut
    Alors utilise mysqldump, ça fait ce que tu cherches : un dump de la structure et des données. C'est un utilitaire en ligne de commande

  3. #3
    Membre chevronné
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2003
    Messages
    1 562
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Février 2003
    Messages : 1 562
    Points : 2 001
    Points
    2 001
    Par défaut
    Citation Envoyé par Florian
    Alors utilise mysqldump, ça fait ce que tu cherches : un dump de la structure et des données. C'est un utilitaire en ligne de commande
    J'ai essayé cet utilitaire mais n'ai pas réussi à le faire fonctionner (d'ailleurs, pas trouvé de man pour cette commande !).

    Je n'ai pas trouvé ses infos d'aide très "parlantes".

    Tu l'utilises couramment ?

    Pour me connecter à ma base mysql, j'indique mon nom de user de la BDD via ligne de commande (de mémoire : >mysql -s user -p) puis tape mon mot de passe. Est-ce la même syntaxe à employer avec mysqldump ?

  4. #4
    Invité
    Invité(e)
    Par défaut
    Copier/coller de paresseux de la doc (pas la dernière mais une 4.0.1X):
    4.9.7 mysqldump, Dumping Table Structure and Data

    Utility to dump a database or a collection of database for backup or for transferring the data to another SQL server (not necessarily a MySQL server). The dump will contain SQL statements to create the table and/or populate the table.

    If you are doing a backup on the server, you should consider using the mysqlhotcopy instead. See section 4.9.8 mysqlhotcopy, Copying MySQL Databases and Tables.

    shell> mysqldump [OPTIONS] database [tables]
    OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
    OR mysqldump [OPTIONS] --all-databases [OPTIONS]

    If you don't give any tables or use the --databases or --all-databases option, entire databases will be dumped.

    You can get a list of the options your version of mysqldump supports by executing mysqldump --help.

    Note that if you run mysqldump without --quick or --opt, mysqldump will load the whole result set into memory before dumping the result. This will probably be a problem if you are dumping a big database.

    Note that if you are using a new copy of the mysqldump program and you are going to do a dump that will be read into a very old MySQL server, you should not use the --opt or -e options.

    mysqldump supports the following options:

    --add-locks
    Add LOCK TABLES before and UNLOCK TABLE after each table dump. (To get faster inserts into MySQL.)
    --add-drop-table
    Add a drop table before each create statement.
    -A, --all-databases
    Dump all the databases. This will be same as --databases with all databases selected.
    -a, --all
    Include all MySQL-specific create options.
    --allow-keywords
    Allow creation of column names that are keywords. This works by prefixing each column name with the table name.
    -c, --complete-insert
    Use complete insert statements (with column names).
    --comments=...
    If set to 0, suppresses additional information (like program version, server version, host) in dumps. The --skip-comments option does the same. Default is 1 to not suppress that information. New in MySQL 4.0.17.
    -C, --compress
    Compress all information between the client and the server if both support compression.
    -B, --databases
    To dump several databases. Note the difference in usage. In this case no tables are given. All name arguments are regarded as database names. USE db_name; will be included in the output before each new database.
    --default-character-set=...
    Sets the character set for the dump. If not specified, `mysqldump' 10.3 (MySQL-4.1.2) or later will use utf8, earlier versions use latin1.
    --delayed
    Insert rows with the INSERT DELAYED command.
    -e, --extended-insert
    Use the new multiline INSERT syntax. (Gives more compact and faster inserts statements.)
    -#, --debug[=option_string]
    Trace usage of the program (for debugging).
    --help
    Display a help message and exit.
    --fields-terminated-by=...
    --fields-enclosed-by=...
    --fields-optionally-enclosed-by=...
    --fields-escaped-by=...
    --lines-terminated-by=...
    These options are used with the -T option and have the same meaning as the corresponding clauses for LOAD DATA INFILE. See section 6.4.8 LOAD DATA INFILE Syntax.
    -F, --flush-logs
    Flush log file in the MySQL server before starting the dump. Note that if you use this option in combination with the --all-databases (or -A) option, the logs will be flushed for each database dumped.
    -f, --force
    Continue even if we get an SQL error during a table dump.
    -h, --host=...
    Dump data from the MySQL server on the named host. The default host is localhost.
    -l, --lock-tables
    Lock all tables before starting the dump. The tables are locked with READ LOCAL to allow concurrent inserts in the case of MyISAM tables. Please note that when dumping multiple databases, --lock-tables will lock tables for each database separately. So using this option will not guarantee your tables will be logically consistent between databases. Tables in different databases may be dumped in completely different states.
    -K, --disable-keys
    /*!40000 ALTER TABLE tb_name DISABLE KEYS */; and /*!40000 ALTER TABLE tb_name ENABLE KEYS */; will be put in the output. This will make loading the data into a MySQL 4.0 server faster as the indexes are created after all data are inserted.
    -n, --no-create-db
    CREATE DATABASE /*!32312 IF NOT EXISTS*/ db_name; will not be put in the output. The above line will be added otherwise, if a --databases or --all-databases option was given.
    -t, --no-create-info
    Don't write table creation information (the CREATE TABLE statement).
    -d, --no-data
    Don't write any row information for the table. This is very useful if you just want to get a dump of the structure for a table!
    --opt
    Same as --quick --add-drop-table --add-locks --extended-insert --lock-tables. Should give you the fastest possible dump for reading into a MySQL server.
    -pyour_pass, --password[=your_pass]
    The password to use when connecting to the server. If you specify no `=your_pass' part, mysqldump you will be prompted for a password.
    -P, --port=...
    Port number to use for TCP/IP connections.
    --protocol=(TCP | SOCKET | PIPE | MEMORY)
    To specify the connect protocol to use. New in MySQL 4.1.
    -q, --quick
    Don't buffer query, dump directly to stdout. Uses mysql_use_result() to do this. Especially useful for big dumps.
    -Q, --quote-names
    Quote table and column names within ``' characters.
    -r, --result-file=...
    Direct output to a given file. This option should be used in MSDOS, because it prevents new line `\n' from being converted to `\n\r' (new line + carriage return).
    --single-transaction
    This option issues a BEGIN SQL command before dumping data from server. It is mostly useful with InnoDB tables and READ_COMMITTED transaction isolation level, as in this mode it will dump the consistent state of the database at the time then BEGIN was issued without blocking any applications. When using this option you should keep in mind that only transactional tables will be dumped in a consistent state, for example, any MyISAM or HEAP tables dumped while using this option may still change state. The --single-transaction option was added in version 4.0.2. This option is mutually exclusive with the --lock-tables option as LOCK TABLES already commits a previous transaction internally.
    -S /path/to/socket, --socket=/path/to/socket
    The socket file to use when connecting to localhost (which is the default host).
    --skip-comments
    Suppresses additional information (like program version, server version, host) in dumps. It does the same as setting --comments to 0. New in MySQL 4.0.17.
    --tables
    Overrides option --databases (-B).
    -T, --tab=path-to-some-directory
    Creates a table_name.sql file, that contains the SQL CREATE commands, and a table_name.txt file, that contains the data, for each give table. The format of the `.txt' file is made according to the --fields-xxx and --lines--xxx options. Note: This option only works if mysqldump is run on the same machine as the mysqld daemon. You must use a MySQL account that has the FILE privilege, and the login user/group that mysqld is running as (normally user mysql, group mysql) must have permission to create/write a file at the location you specify.
    -u user_name, --user=user_name
    The MySQL user name to use when connecting to the server. The default value is your Unix login name.
    -O name=value, --set-variable=name=value
    Set the value of a variable. The possible variables are listed below. Please note that --set-variable=name=value and -O name=value syntax is deprecated as of MySQL 4.0. Use --name=value instead.
    -v, --verbose
    Verbose mode. Print out more information on what the program does.
    -V, --version
    Print version information and exit.
    -w, --where='where-condition'
    Dump only selected records. Note that quotes are mandatory:
    "--where=user='jimf'" "-wuserid>1" "-wuserid<1"

    -X, --xml
    Dumps a database as well formed XML
    -x, --first-slave
    Locks all tables across all databases.
    --master-data
    Like --first-slave, but also prints some CHANGE MASTER TO commands which will later make your slave start from the right position in the master's binlogs, if you have set up your slave using this SQL dump of the master.
    -O net_buffer_length=#, where # < 16M
    When creating multi-row-insert statements (as with option --extended-insert or --opt), mysqldump will create rows up to net_buffer_length length. If you increase this variable, you should also ensure that the max_allowed_packet variable in the MySQL server is bigger than the net_buffer_length.
    The most normal use of mysqldump is probably for making a backup of whole databases. See section 4.5.1 Database Backups.

    mysqldump --opt database > backup-file.sql

    You can read this back into MySQL with:

    mysql database < backup-file.sql

    or

    mysql -e "source /path-to-backup/backup-file.sql" database

    However, it's also very useful to populate another MySQL server with information from a database:

    mysqldump --opt database | mysql --host=remote-host -C database

    It is possible to dump several databases with one command:

    mysqldump --databases database1 [database2 ...] > my_databases.sql

    If all the databases are wanted, one can use:

    mysqldump --all-databases > all_databases.sql

  5. #5
    Membre chevronné
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2003
    Messages
    1 562
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Février 2003
    Messages : 1 562
    Points : 2 001
    Points
    2 001
    Par défaut
    Ohhh, merci c'est trop !

    J'essaie dès que possible, merci bcp !

  6. #6
    Invité
    Invité(e)
    Par défaut
    Je te conseille de récupérer les docs sur le site de mysql
    et je t'engage à mettre "résolu" si c'est le cas.

  7. #7
    Membre chevronné
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2003
    Messages
    1 562
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Février 2003
    Messages : 1 562
    Points : 2 001
    Points
    2 001
    Par défaut
    Citation Envoyé par Florian
    Je te conseille de récupérer les docs sur le site de mysql
    Je pense que cette commande doit fonctionner :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    > mysqldump -u user --opt database > backup.sql
    Citation Envoyé par Florian
    et je t'engage à mettre "résolu" si c'est le cas.
    Dès que j'essaie et si ça fonctionne, je mets le tag, promis !

  8. #8
    Membre chevronné
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2003
    Messages
    1 562
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Février 2003
    Messages : 1 562
    Points : 2 001
    Points
    2 001
    Par défaut
    Merci pour ton aide

    La page d'info du mysqldump de mon MySql 3.23.52 n'était pas aussi clair ni aussi précis.

    Pour ceux que ça pourrait intéresser, ce qui fonctionne chez moi :

    >mysqldump -u USER -p --databases BDD > /home/USER/backup.sql

  9. #9
    Invité
    Invité(e)
    Par défaut
    Si tu n'es pas en 4.0.x, passes y,le cache de requête est une fonction font on ne peut pas se passer

  10. #10
    Membre chevronné
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Février 2003
    Messages
    1 562
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Février 2003
    Messages : 1 562
    Points : 2 001
    Points
    2 001
    Par défaut
    Citation Envoyé par Florian
    Si tu n'es pas en 4.0.x, passes y,le cache de requête est une fonction font on ne peut pas se passer
    J'y passerai bientôt lorsque je troquerai ma bonne vieille Mandrake 9.0 contre une version plus récente

    Mais tu sais, dans mon projet, la base de données ne sert vraiment à rien d'autre qu'à stocker des données que j'interroge ou met à jour via requètes simples SQL depuis des programmes Perl. Et je n'ai pas non plus 50 millions d'enregistrements, c'est vraiment une BDD basique

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 3
    Dernier message: 30/06/2014, 23h56
  2. Réponses: 2
    Dernier message: 08/04/2011, 11h12
  3. Sauvegarde automatique d'une base mysql.
    Par super-java dans le forum Administration
    Réponses: 6
    Dernier message: 04/12/2008, 16h35
  4. Réponses: 6
    Dernier message: 26/09/2007, 08h55
  5. Réponses: 3
    Dernier message: 05/06/2006, 16h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo