Re: [e-smith-devinfo] Automating MySQL commands

2002-02-09 Thread Greg Zartman


Dan Brown <[EMAIL PROTECTED]> said:

Another option would be to use the perl DBI module.  The dbd::mysql DBI 
drivers contains a fairly wide array of mysqladmin functions via the admin
() method call.  To create a table or tables, the following code could be 
used:

#Attach modules
use DBI;
use strict;

#Set DBI for manual error handling
my %dbiAttr = (
   PrintError => 0,
   RaiseError => 0
  );

#Open a connection to mysql
my $dbh = DBI->connect( "dbi:mysql:databasename", "username", "password",\
%dbiAttr) || die $DBI::errstr;

#Prepare SQL statement
my $sth = $dbh->prepare("CREATE TABLE table1 (
 key int(10) NOT NULL ,
 field1 char(5),
 PRIMARY KEY(key))") || die $DBI::errstr

#Execute SQL statment
$sth->execute() || die $DBI::errstr;

#Close mysql connection
$sth->finish;
$dbh->disconnect;

This is a pretty basic example, but works none the less.  As long as have 
the appropriate username and password, you're set.


Regards,


-- 
Greg J. Zartman, P.E.
Vice-President

Logging Engineering International, Inc.
1243 West 7th Avenue
Eugene, Oregon 97402
541-683-8383fax 541-683-8144


--
Please report bugs to [EMAIL PROTECTED]
Please mail [EMAIL PROTECTED] (only) to discuss security issues
Support for registered customers and partners to [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Archives by mail and http://www.mail-archive.com/devinfo%40lists.e-smith.org




Re: [e-smith-devinfo] Automating MySQL commands

2002-02-09 Thread Jason Miller

On Sat, 9 Feb 2002, Dan Brown wrote:

>  
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
> 
>   I'm working on putting together a package that will need to add some
> MySQL tables.  I'm thinking I should be able to add "mysql <
> /path/to/script.sql" in a post-install script in the RPM.  Those
> commands run as root, so I'd expect it should grab the mysql root
> password from /root/.my.cnf.  Anybody know different before I try it?

Your best route is to take advantage of the mysql.init service included in
the e-smith-mysql rpm.

Make your post-install script make a symlink into the directory
/etc/e-smith/sql/init

i.e.

symlink "/etc/e-smith/sql/your-package/table-schema.sql,
"/etc/e-smith/sql/init/S10table-schema.sql";

Then, the bootstrap-console-save action will automatically start the
mysql.init service (or you can do it manually: /etc/rc.d/init.d/mysql.init
start) and the files in the /etc/e-smith/sql/init directory will
automatically be accessed as "root" and the SQL code in them run.

It acts something like the event-action model in that the files in
/etc/e-smith/sql/init are run in the alphabetical order they are found (so
if you have several .sql files, make sure you make the symlinks in the
right order).

And the reason for the symlinks is because mysql.init will delete the files
in /etc/e-smith/sql/init after it has uploaded them.  So, to have that
legacy information around for reference purposes, I prefer the symlink
file approach.

Aside from that, to answer your specific question, if you are logged in as
"root" and run the action you mention above, it will automatically read the
/root/.my.cnf file for its password.

Regards,

Jay

-- 
Jason D. Miller E-mail: [EMAIL PROTECTED]
Senior Software Developer   Phone:  +1 613.368.4387
Network Server Solutions Group  Fax:+1 613.564.7739
Mitel Networks Corporation  http://www.e-smith.com

"Are those workers dead?"
"Technically, yes ... but that's no excuse!", ,
"Back to work you lazy corpse! ..."
--- Taken from DilbertTV, "Elbonian Trip"


--
Please report bugs to [EMAIL PROTECTED]
Please mail [EMAIL PROTECTED] (only) to discuss security issues
Support for registered customers and partners to [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Archives by mail and http://www.mail-archive.com/devinfo%40lists.e-smith.org




[e-smith-devinfo] Automating MySQL commands

2002-02-09 Thread Dan Brown

 
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

I'm working on putting together a package that will need to add some
MySQL tables.  I'm thinking I should be able to add "mysql <
/path/to/script.sql" in a post-install script in the RPM.  Those
commands run as root, so I'd expect it should grab the mysql root
password from /root/.my.cnf.  Anybody know different before I try it?

- -- 
Dan Brown, KE6MKS, [EMAIL PROTECTED]
"Since all the world is but a story, it were well for thee to buy the
more enduring story rather than the story that is less enduring."
 -- The Judgment of St. Colum Cille 

-BEGIN PGP SIGNATURE-
Version: PGP 7.0.4

iQA/AwUBPGXRfH6CI7gsQbX8EQKS6ACfTIg9zJYSkbPokSXY57asENPiIOQAn20/
ePGahO4fGovryXr+GVA0nynG
=EaIK
-END PGP SIGNATURE-


--
Please report bugs to [EMAIL PROTECTED]
Please mail [EMAIL PROTECTED] (only) to discuss security issues
Support for registered customers and partners to [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Archives by mail and http://www.mail-archive.com/devinfo%40lists.e-smith.org