2

Can this command be scripted?

$ mysqladmin -u username -p create databasename

I'd like to do it for multiple names all at once? Also I'd like to then set permissions for all of them at once as well. I'm not sure how to do this?

slm
  • 369,824
cea
  • 1,543

1 Answers1

3

For the first question, it's trivial:

$ for db in fred barney wilma ; do mysqladmin -u username -p create $db ; done

As for setting permissions, that's complicated enough that you might as well just write a script.

Consider that it is possible to write a text file full of SQL and then load it into the DB in a single go:

$ mysql -u username -p$pass $db < stuff.sql

Note that the mysql(1) command has two forms for the -p flag: if there is a space after it, it tells it to ask the user interactively for the password. If you follow -p with a password, without a space between them, it uses that instead. This is less secure, naturally.

Warren Young
  • 72,032
  • Sorry I'm not following the "trivial' part you mention ha but am strangely following the second part. What do you mean "for db in .."? – cea Oct 27 '13 at 04:56
  • $ indicates a Bourne shell command. So, type that at any Bourne type shell, listing your database names in place of the example names (fred, barney, wilma) that I have given. – Warren Young Oct 27 '13 at 12:03