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

"J.O. Aho" <[email protected]> Thu, 2 Nov 2023 12:03:13 +0100
Newsgroups comp.databases.mysql
Message-ID <[email protected]>
On 02/11/2023 09.50, ^Bart wrote:
>> You don't need anything but SQL and the CLI.
> 
> Ok!
> 
>> 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.
> 
> Ok.
> 
>> Then use the CLI source command to run that file, i.e.
>>
>> mysql -u user -ppassword < reload.sql
> 
> So... I should have a file where I'll store the login data and I could 
> name it like "login.sql" and inside of it I should insert the "reload.sql".

No, the sql file will only include the raw SQL queries in the same way 
as you would have when you type in the mysql after you logged in.

Credentials can be stored in a configuration file, here is an example 
for MySQL, but works exactly the same way for MariaDB:

https://www.serverlab.ca/tutorials/linux/database-servers/how-to-create-a-credential-file-for-mysql/

In you case I would maybe create a new user, create a profile (I hope 
this part is in MariaDB). See to that the default login shell is 
/sbin/nologin and then you see to that the cronjob is run as this user 
(in this example: dbcronuser).

* 5 * * * dbcronuser (mysql --login-path=backups < 
/home/dbcronuser/reload.sql)

-- 
  //Aho