The script is very similar to Magento 1.x:
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE log_url;
TRUNCATE log_url_info;
TRUNCATE log_visitor;
TRUNCATE log_visitor_info;
TRUNCATE report_event;
TRUNCATE report_viewed_product_index;
TRUNCATE report_compared_product_index;
TRUNCATE report_viewed_product_aggregated_daily;
SET FOREIGN_KEY_CHECKS=1;
A new solution:
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE cron_schedule;
TRUNCATE customer_log;
TRUNCATE customer_visitor;
TRUNCATE report_compared_product_index;
TRUNCATE report_event;
TRUNCATE report_viewed_product_aggregated_daily;
TRUNCATE report_viewed_product_aggregated_monthly;
TRUNCATE report_viewed_product_aggregated_yearly;
TRUNCATE report_viewed_product_index;
SET FOREIGN_KEY_CHECKS=1;
DELETE FROM session; OPTIMIZE TABLE session;