问题
I created This shell script below, which fetches data from MySQL and create output as csv file. but I want to create this csv with a timestamp. so I just want filename to be like this result_ddmmyy.csv
Is there any way to do this from script or from SQL query.
#!/usr/bin/bash
#scirpt to connect with db
master_db_user='root'
master_db_passwd='123'
master_db_port='3306'
master_db_host='localhost'
master_db_name='sagar_tb'
#Preparing script
#MySql Command to connect to a database
mysql -u$master_db_user -p$master_db_passwd -D$master_db_name -e 'select * into outfile "/created_files/result931.csv" fields terminated by "," lines terminated by "\n" from sagar_tb.test_table;'
echo "End of the Script"
Thanks and Regards, Sagar Mandal
回答1:
Add below commands in your script and update here if it works
now=$(date +"%y%m%d")
And later add this in your file creation
"/created_files/result_${now}.csv"
来源:https://stackoverflow.com/questions/61039141/sql-query-that-create-csv-file-with-timestamp-on-it