MySQL load large sql file And Export large table into CSV
To load a large SQL file into the database (or as database).
-- In Windows Run MySQL command line client from the start menu:
-- console will open, provide MySQL password
-- select your database
use <name_of_your_database>;
-- run below command provide your SQL file path
source <path_of_your_.sql>
For example:
source F:\iConsult Work\Tipp - Trade Information Portal\3years_TradeStat_FullData.sql
-- In linux upload that SQL file in public_html from cpanel, then copy the path of that file from cron job
-- go/run terminal from cpanel, then connect the database with 'mysql -u user_name -p' command.
-- then select your database with 'use your_database' command
-- and then execute the below command after changing the path after source keyword.
For example:
source /home/dhalabga/public_html/tiger_data_backup_tiger_force_backup.sql
To export / load large table data into file(csv)
-- This will export large table data into CSV, but before this, you have to set secure_file_priv = "" in my.ini in windows and my.cnf in Linux for more info check the below link:
-- https://sebhastian.com/mysql-fix-secure-file-priv-error/#:~:text=The%20secure_file_priv%20value%20is%20a,it%20directly%20using%20SQL%20query.&text=To%20change%20the%20value%20of,variable%20under%20%5Bmysqld%5D%20options.
-- Save the file and then restart MySQL service.
-- Do not create a CSV file, just provide the path and file name it will create the file itself.
select * from <TableName> INTO OUTFILE <'path'> FIELDS ENCLOSED BY '"' TERMINATED BY ';' ESCAPED BY '"' LINES TERMINATED BY '\r\n';
For Example:
SELECT * FROM 3years_tradestat_fulldata INTO OUTFILE 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/myExportFile.csv' FIELDS ENCLOSED BY '"' TERMINATED BY ';' ESCAPED BY '"' LINES TERMINATED BY '\r\n';
Comments
Post a Comment