Re: From bash script (Debian Bookworm) login and query to MariaDB

Jerry Stuckle <[email protected]> Tue, 31 Oct 2023 19:06:48 -0400
Newsgroups comp.databases.mysql
Organization A noiseless patient Spider
Message-ID <[email protected]>
On 10/31/2023 11:42 AM, ^Bart wrote:
> Hi guys,
> 
> I need to write in bash a script which do these things:
> 
> 1) Login to MariaDB;
> 2) Truncate a table to make it empty;
> 3) Import data from a file to this table.
> 
> I found this guide 
> https://notearena.com/lesson/how-to-access-databasemysql-mariadb-in-linux-shell-scripting/ and I'd like to know if it's the right way! :)
> 
> Now I do everything manually...
> 
> Regards.
> ^Bart

You don't need anything but SQL and the CLI.

Just create a text file with the SQL commands necessary to use the 
database, truncate the table and import from the file.  Call it 
reload.sql, for instance.

Then use the CLI source command to run that file, i.e.

mysql -u user -ppassword
source reload.sql

Or you could do it with

mysql -u user -ppassword < reload.sql


It's not a good idea to have the password in a file.

-- 
==================
Remove the "x"'s from my email address
Jerry Stuckle
[email protected]
==================