Storing a username and password via Applescript?

I want to write an Applescript library to access my MySQL on localhost so that I can simplify running such commands as:

set myResult to do shell script "/Applications/MAMP/Library/bin/mysql --host=localhost --user=root --password=pw -D 'books_db' -e \"SELECT title, author, publisher, length FROM books_list WHERE author LIKE '%" & searchResult & "%'\""

Is there a way to safely store the variables here (user, password) somewhere on the Mac? I thought there might be a way to get into Keychain Access, but looking in Script Debugger it doesn’t look like it is scriptable.

The idea would be that on first run of any of the commands, it would check, set or get the variables for your database.

Any suggestions?

If you use my BridgePlus library, it has ASObjC commands for retrieving passwords from a keychain.

https://latenightsw.com/support/freeware/

Thanks Shane. I will have a look at this.