Maison  >  Article  >  base de données  >  Comment utiliser mysqlfrm pour restaurer la structure de la table frm

Comment utiliser mysqlfrm pour restaurer la structure de la table frm

一个新手
一个新手original
2017-10-17 10:08:433508parcourir

1.installation de mysqlfrm

-----------------------------

Puisque mysqlfrm fait partie de l'outil mysql-utilities, nous pouvons installer mysql-utilities, télécharger le package de code source correspondant, puis le compiler et l'installer.

shell> tar -xvzf mysql-utilities-1.6.4.tar.gz 
shell> cd mysql-utilities-1.6.4
shell> python ./setup.py build
shell> python ./setup.py install

Une fois l'installation terminée, mysqlfrm et d'autres fichiers exécutables seront disponibles dans le répertoire d'exécution python correspondant.

2. Introduction aux paramètres liés à mysqlfrm

----------------------------------- - -----

--basedir :如 --basedir=/usr/local/percona-5.6.21
--server : 如 --server=user:password@192.168.1.100:3306
--diagnostic : 开启按字节模式来恢复frm结构
--user :启动MySQL用户,通过为mysql

3. Utilisez mysqlfrm

------------------- - -----

Utilisez le mode --basedir pour restaurer :

[ 16:35:29-root@br3cy1sw:~ ]# mysqlfrm --basedir=/usr/local/percona-5.6.21/ /root/t1.frm --port=3434 --user=mysql --diagnostic
# WARNING The --port option is not used in the --diagnostic mode.
# WARNING: The --user option is only used for the default mode.
# WARNING: Cannot generate character set or collation names without the --server option.
# CAUTION: The diagnostic mode is a best-effort parse of the .frm file. As such, it may not identify all of the components of the table correctly. This is especially true for damaged files. It will also not read the default values for the columns and the resulting statement may not be syntactically correct.
# Reading .frm file for /root/t1.frm:
# The .frm file is a TABLE.
# CREATE TABLE Statement:
CREATE TABLE `root`.`t1` (
`a` int(11) NOT NULL,
`b` int(11) DEFAULT NULL,
`c` int(11) DEFAULT NULL,
`d` varchar(600) DEFAULT NULL,
PRIMARY KEY `PRIMARY` (`a`),
KEY `idx_t1_bc` (`b`,`c`)
) ENGINE=InnoDB;
    #...done.

Utilisez le mode --server pour restaurer :

[ 16:35:10-root@br3cy1sw:~ ]#mysqlfrm --server=user:password@192.168.1.100:3306 /root/t1.frm --port=3434 --user=mysql --diagnostic
WARNING: Using a password on the command line interface can be insecure.
# WARNING The --port option is not used in the --diagnostic mode.
# WARNING: The --user option is only used for the default mode.
# Source on 192.168.1.100: ... connected.
# CAUTION: The diagnostic mode is a best-effort parse of the .frm file. As such, it may not identify all of the components of the table correctly. This is especially true for damaged files. It will also not read the default values for the columns and the resulting statement may not be syntactically correct.
# Reading .frm file for /root/t1.frm:
# The .frm file is a TABLE.
# CREATE TABLE Statement:
CREATE TABLE `root`.`t1` ( `a` int(11) NOT NULL, `b` int(11) DEFAULT NULL, `c` int(11) DEFAULT NULL,
`d` varchar(200) COLLATE `utf8_general_ci` DEFAULT NULL,
PRIMARY KEY `PRIMARY` (`a`),
KEY `idx_t1_bc` (`b`,`c`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    #...done.

Avez-vous remarqué que le varchar restauré à l'aide de --basedir est 3 fois supérieur à celui du mode --server ? Cela devrait être dû au fait que mysqlfrm n'est pas en mesure d'effectuer la vérification de l'encodage des caractères lors de l'utilisation du mode basedir ? .

Regardez à nouveau le fichier --server : (concentrez-vous sur le texte en rouge et en gras), suggestion : Lorsque le mode --server peut être utilisé, essayez d'utiliser --server et assurez-vous que le fichier mysqld L'environnement est fourni conformément à l'environnement de production d'origine.

--server=server
Connection information for a server. Use this option or --basedir for the default mode.
 
If provided with the diagnostic mode, the storage engine and character set information are validated against this server.

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn