powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / MySQL [игнор отключен] [закрыт для гостей] / Импорт в БД mysql из CSV
2 сообщений из 2, страница 1 из 1
Импорт в БД mysql из CSV
    #38666048
seg856
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Пытаюсь залить в БД файл csv.

LOAD DATA INFILE 'c:\\pasport.csv']
[INTO TABLE `pr_person`
character set cp1251
FIELDS TERMINATED BY ';' ENCLOSED BY '"' ESCAPED BY '\\'
LINES STARTING BY '' TERMINATED BY '\r\n' ;

Программа ругается на дату dtrod. Наверное, потому что в csv формат даты dd.mm.yyyy, в mysql формат yyyy-mm-dd. Как залить файл в связи с этим?
...
Рейтинг: 0 / 0
Импорт в БД mysql из CSV
    #38666085
tanglir
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Use the forcegoogleFM, Luke!

http://dev.mysql.com/doc/refman/5.1/en/load-data.html
первый же коммент:
авторConverting strings into dates while loading data using LOAD DATA INFILE:

In the following example, we are trying to convert the data in the file for date columns col3, col4 in formats 'mm/dd/yyyy', 'dd/mm/yyyy' into MySQL standard YYYY-mm-dd respectively.

load data infile '/tmp/xxx.dat'
into table xxx
fields terminated by '|'
lines terminated by '\n'
(col1,
col2,
@col3,
@col4,
col5)
set
col3 = str_to_date(@col3, '%m/%d/%Y'),
col4 = str_to_date(@col4, '%d/%m/%Y')
;

You could convert into any format you want by using the date_format function around the str_to_date().

Example:
...
set col2 = date_format(str_to_date(@col2, 'format'), 'your format')
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / MySQL [игнор отключен] [закрыт для гостей] / Импорт в БД mysql из CSV
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]