http://stackoverflow.com/questions/12426320/how-do-i-set-the-default-schema-for-a-user-in-mysql http://stackoverflow.com/questions/12426320/how-do-i-s ...
http://stackoverflow.com/questions/12426320/how-do-i-set-the-default-schema-for-a-user-in-mysql
up vote16down votefavorite 2 |
Is there a way to set a default schema for each user in MySQL and if so how? Where user x would default to schema y and user z would default to schema a. mysql user default database-schema
|
||||||||||||
|
2 Answers
activeoldestvotesup vote27down voteaccepted |
There is no default database for user. There is default database for current session. You can get it using DATABASE() function -
And you can set it using USE statement -
You should set it manually - |
========================
http://stackoverflow.com/questions/1820971/set-current-database-in-mysql-script
6down votefavorite 1 |
I have a script file for MySQL that needs to be run on about 30 databases. Here's a snippet:
There are many more lines in this script and I'd like to automate it in a loop of current databases to be updated. I've got the list and the loop down using cursors, but here's where I'm running into trouble: When I'm on a particular database in the cursor, that database name is in a variable. I can't just say ALTER TABLE curschema.
The problem is, setting up executable strings (like above) will become an extremely tedious task with the dozens of lines of code that I have to run. I was hoping that there was a way that I could set the current database for operations and then just reset that database each loop pass so my generic statements might be run: (start of my loop) SET DATABASE database0 -- (through to database29) -- run statements with database0 .... 29 being implied with the above command
(end of my loop) Does such a command exist to set the current database on which operations may be performed? If no such command exists, is there an easier way to accomplish my task? I figure that at this juncture it's just easier to do a find/replace on all the database names 30 times than it is to rewrite my entire script file to be executable/parameter-ized strings. Thanks! mysql database
|
|||
add a comment |
1 Answer
activeoldestvotesup vote16down voteaccepted |
Did you try
Example:
|