Search code examples
mysqlunixmysqlimport

Is it possible to set MySQL session variables using mysqlimport?


I have an import job that uses unix's mysqlimport, and the source data is undependable, so I need to set sql_mode="NO_ENGINE_SUBSTITUTION" so that the job doesn't fail if there is an error. I'd prefer to do this just for the individual job, but I don't know if it's possible. Does anyone know?

Current command:

mysqlimport --compress --fields-terminated-by="," --fields-optionally-enclosed-by='"' --lines-terminated-by="\n" --replace --local --user=username --password=password -h localhost dbname company_data.txt


Solution

  • I'm not familiar with mysqlimport, but the manual doesn't list an option for that.

    Since mysqlimport is just a command-line interface to the LOAD DATA INFILE SQL statement, a workaround would be this:

    mysql -uuser -ppassword dbname -e "set session sql_mode='NO_ENGINE_SUBSTITUTION'; LOAD DATA INFILE 'company_data.txt' INTO ..." /*you can figure out the rest*/
    

    Here's the manual entry for LOAD DATA INFILE.