0% found this document useful (0 votes)
37 views15 pages

15 Importing and Exporting

This document discusses importing and exporting data in MySQL. It covers using LOAD DATA INFILE to import data from text files into tables, specifying options like ignoring lines, columns to import, and data transformations. It also covers using SELECT...INTO OUTFILE to export data from tables to text files. Finally, it mentions using mysqldump to export an entire database or table to a SQL file.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views15 pages

15 Importing and Exporting

This document discusses importing and exporting data in MySQL. It covers using LOAD DATA INFILE to import data from text files into tables, specifying options like ignoring lines, columns to import, and data transformations. It also covers using SELECT...INTO OUTFILE to export data from tables to text files. Finally, it mentions using mysqldump to export an entire database or table to a SQL file.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

15.

Importing and Exporting Data


15.1 Import and Export Operations

• Importar
– LOAD DATA INFILE
– Desde línea de comando:
• mysqlimport

• Exportar
– SELECT … INTO OUTFILE
– Desde línea de comando:
• mysqldump
Permite:
• Especificar nombre de archivo a cargar
• Ubicación del archivo
• Ignorar líneas al inicio del archivo
• Cuáles columnas importar
• Ignorar o transformar columnas
• Cómo manejar duplicados
15.2.1 Importing data with LOAD DATA INFILE

• Crear tabla Localidades con:


– Entidad Char(2)
– Municipio Char(3)
– Localidad Char(4)
– Nombre Varchar(30)
– Población Int
• Importar los datos del archivo Localidades.txt
LOAD DATA INFILE 'f:/Localidades.txt‘
INTO TABLE Localidades;
LOAD DATA INFILE 'f:/Localidades.txt‘
INTO TABLE Localidades
IGNORE 1 LINES
(cve, @muni, nom_localidad, poblacion);

LOAD DATA INFILE 'f:/Localidades.txt‘


INTO TABLE Localidades
FIELDS

IGNORE 1 LINES
(cve, @muni, nom_localidad, @pob)
SET poblacion=@pob*1.10;
• Importar los datos del archivo Localidades.txt
en una tabla con el número de localidad y el
nombre.

• 240010001
• Número de localidad = 0001
LOAD DATA INFILE 'f:/Localidades.txt'
INTO TABLE localnum
IGNORE 1 LINES
(@clave, nomlocalidad)
SET numLocalidad=RIGHT(@clave,4);
15.2.2 Exporting data with SELECT … INTO
OUTFILE

Exportar los atributos pers_id y name de la


tabla PERSONAL a un archivo de texto llamado
PERSONAS.TXT

Exportar todos los atributos de la tabla


PERSONAL a un archivo de texto llamado
PERSONAS2.TXT, separando los campos con
comas y encerrados entre comillas.
• Importar el archivo Municipios.xlsx a una tabla en
MySQL.

• Importar el archivo Municipios.xlsx a una tabla en


MySQL. Separar la clave del municipio para crear:
– Clave Entidad (dos primeros caracteres de clave)
– Clave Municipio (tres últimos caracteres de clave)
– Definir primary key con Clave entidad y Clave
Municipio
SELECT pers_id, name
INTO OUTFILE 'F:/PERSONAS.TXT‘
FROM PERSONAL
15.3.2 Exporting data with mysqldump

Exporta la tabla BDPRIM2013 con mysqldump


15.3.2 Exporting data with mysqldump

mysqldump -u root bdprim2013 > copia.sql

mysqldump –tab=f:/ -u root bdprim2013


localidad

mysqldump --tab=dir_name options db_name


tbl_name

You might also like