Assuming your image files are contained in a single directory:
$ ls -al ./folder_img/*.png
-rw-rw-r-- 1 lacobus lacobus 349237 Jul 4 18:03 ./folder_img/alpha.png
-rw-rw-r-- 1 lacobus lacobus 312568 Jul 4 18:03 ./folder_img/beta.png
-rw-rw-r-- 1 lacobus lacobus 159315 Jul 4 18:03 ./folder_img/delta.png
-rw-rw-r-- 1 lacobus lacobus 2453952 Jul 4 18:03 ./folder_img/episilon.png
-rw-rw-r-- 1 lacobus lacobus 482526 Jul 4 18:03 ./folder_img/gamma.png
-rw-rw-r-- 1 lacobus lacobus 848590 Jul 4 18:03 ./folder_img/omega.pn
You can use the find
utility to generate an SQL script from the image files contained in this directory, in a non-recursive way. The following example writes a SQL script to the file script.sql
, see:
$ find ./folder_img -maxdepth 1 -iname "*.png" -type f -exec \
echo "INSERT INTO tb_imagem (nome_arquivo) VALUES ('{}');" \; > script.sql
Output (% with%):
INSERT INTO tb_imagem (nome_arquivo) VALUES ('./folder_img/delta.png');
INSERT INTO tb_imagem (nome_arquivo) VALUES ('./folder_img/alpha.png');
INSERT INTO tb_imagem (nome_arquivo) VALUES ('./folder_img/gamma.png');
INSERT INTO tb_imagem (nome_arquivo) VALUES ('./folder_img/beta.png');
INSERT INTO tb_imagem (nome_arquivo) VALUES ('./folder_img/episilon.png');
INSERT INTO tb_imagem (nome_arquivo) VALUES ('./folder_img/omega.png');
To run the generated script in your database:
$ mysql -h [servidor] -u [usuario] -p [senha] -D [database] < script.sql