본문 바로가기

Database/MySQL

MySQL shell importTable() 사용하기

filelist="
T1.csv
T2.csv
"

HOST=127.0.0.1
PASSWD=pass
DATABASE=test

USER=root
THREADS=4
file_path=/home/chlee/data

CMD="$HOME/mysqlsh/bin/mysqlsh -h $HOST -u$USER -p$PASSWD --mysql"

function importAll()
{
   for filename in `ls $filelist`
   do
      importTable $file_path/$filename
   done
}

function importTable()
{
   if [ -f "$1" ];
   then
      basename=$(basename -- $1)
      filename=${basename%.*}

      echo "import $filename"  
      time $CMD -e "util.importTable('$1', {schema: '$DATABASE', table: '${filename%.*}_pt', dialect: 'csv-unix', skipRows: 0, showProgress: true, fieldsOptionallyEnclosed: true, fieldsTerminatedBy: ',', linesTerminatedBy: '\n',fieldsEnclosedBy: '\"',threads: $THREADS , bytesPerChunk: '200M'})"
   else
      echo "$1 does not exists."
   fi

}

if [ "$#" = 0 ];
then
   importAll
elif [ "$#" = 1 ];
then
   importTable $1
fi

'Database > MySQL' 카테고리의 다른 글

InnoDB Buffer pool  (0) 2021.10.01
InnoDB Locking and Transaction Model  (0) 2021.10.01
MySQL shell exportTable() 사용하기  (0) 2021.10.01
MySQL 쿼리로 csv 데이터 추출하기  (0) 2021.10.01
purge binary logs statement  (0) 2020.11.17