Skip to content

Instantly share code, notes, and snippets.

@ivanitskiy
Last active January 30, 2020 17:47
Show Gist options
  • Save ivanitskiy/075662907d8e7b469bd020d8e64e2360 to your computer and use it in GitHub Desktop.
Save ivanitskiy/075662907d8e7b469bd020d8e64e2360 to your computer and use it in GitHub Desktop.
Read data from mysql SQL and insert into clickhouse
SQL=$(cat <<EOF
SELECT
id, DATE_FORMAT(created_at, "%Y-%m-%d"),
type, user_id, location_id, UNIX_TIMESTAMP(created_at)
FROM hits
EOF
)
mysql -h source_db_host mydb -BNe "$sql" > hist.txt
cat hist.txt | clickhouse-client -d mydb --query="INSERT INTO hits FORMAT TabSeparated"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment