List:General Discussion« Previous MessageNext Message »
From:Travis Ard Date:July 29 2010 8:19pm
Subject:RE: Variable Expansion Using MySQL Client and .sql Files
View as plain text  
You could try it inside a "here" document:

mysql <<EOF
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER ON concrete5.db TO
'admin'@'localhost' IDENTIFIED BY '$PASSWD_PRIV_ROOT';
EOF

----------------------------------------
> Date: Thu, 29 Jul 2010 14:29:55 -0500
> From: todd_dsm@stripped
> To: mysql@stripped
> Subject: Variable Expansion Using MySQL Client and .sql Files
>
> Hey all,
>
> I've found many packages that sit on top of MySQL for various clients.
> For the purposes of consistency I'd like to automate these installs.
> I've been directed towards using .sql files and they work great.
>
> The trouble I'm having now is that I would like to secure the
> installation but variable expansion isn't clicking for me.
>
> My setup is fairly straight-forward:
>
> I have a single installer script that calls all other scripts. This is
> how it works:
> 1) Source in all global environment variables from a working file:
> 1_GLOBAL_ENV.sh
> 2) execute script to create mysql db
> 3) secure mysql
>
> . /root/payload/1_GLOBAL_ENV.sh
> ...
> ###---
> ### Configure MySQL
> ###---
> set -x
> mysql -v < ${INST_SCRIPTS}/mysqld/secure_mysqld.sql
> ...
> mysql -v < ${INST_SCRIPTS}/mysqld/create_db.sql
> ...
> ---
>
> The create_db.sql should be similar to this:
> Concrete5, for example needs:
> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, ALTER ON
> concrete5.db TO 'admin'@'localhost' IDENTIFIED BY '$PASSWD_PRIV_ROOT';
> ---
>
> The secure_mysqld.sql script is fairly simple as well:
>
> # Display the current user:
> select user();
>
> # Display all default accounts:
> SELECT User,Host,password FROM mysql.user;
>
> # Remove anonymous accounts:
> DELETE FROM mysql.user WHERE user = '';
>
> # Display all remaining accounts:
> SELECT User,Host,password FROM mysql.user;
>
> # Sync root passowrds:
> UPDATE mysql.user SET Password = PASSWORD('$PASSWD_PRIV_ROOT') WHERE
> User = 'root';
>
> exit
> ---
>
> It all works pretty well. Variable expansion is the problem. For now all
> of my other scripts substitute $PASSWD_PRIV_ROOT (from my
> 1_GLOBAL_ENV.sh) for the actual password. The *.sql scripts do not.
>
> If anyone can shed some light on this I would appreciate the help.
>
> --
> Thanks for the assist,
>
> Todd E Thomas
> C: 515.778.6913
> "It's a frail music knits the world together."
> -Robert Dana
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?unsub=1
>
 		 	   		  
Thread
Variable Expansion Using MySQL Client and .sql FilesTodd E Thomas29 Jul
  • RE: Variable Expansion Using MySQL Client and .sql FilesTravis Ard29 Jul
    • Re: Variable Expansion Using MySQL Client and .sql FilesTodd E Thomas30 Jul