Can I set a value for other fields in mysql when loaddatainfile is used? For example, I have a table with four fields: a, B, c, and d. The txt file for load data only contains the values of three fields (a, B, and c, can I set a value for field d of each record while importing it? (Such as the user name of the operation)
Reply to discussion (solution)
Load data infile syntax
Load data [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name.txt'
[REPLACE | IGNORE]
Into table tbl_name
[FIELDS
[Terminated by 'string']
[[OPTIONALLY] enclosed by 'char ']
[Escaped by 'char ']
]
[LINES
[Starting by 'string']
[Terminated by 'string']
]
[IGNORE number LINES]
[(Col_name_or_user_var,...)]
[SET col_name = expr,...)]
The red ones should meet your requirements.
Note: the character set indicated by character_set_database system variables is used to interpret information in the file. The setting of set names and character_set_client does not affect the interpretation of input.