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.
How do I set the default schema for a user in…
2018-06-17 22:51:10来源:未知 阅读 ()
http://stackoverflow.com/questions/12426320/how-do-i-set-the-default-schema-for-a-user-in-mysql
up vote16down votefavorite
2
|
mysql user default database-schema
|
||
add a comment
|
2 Answers
up 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
up vote16down voteaccepted
|
Did you try
Example:
|
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
下一篇:laravel步骤 (我是新手)
- [mysql相关集锦] 001 - mysql zip安装/The service already 2019-07-24
- Mysql中如何使用find_in_set 2019-06-13
- MySQL中find_in_set()函数的使用 2018-07-24
- mysql 使用set names 解决乱码问题的原理 2018-07-13
- MySQL chartset 2018-07-09
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash
x
andz
MySQL users, or users of some other system (e.g. your OS)? Do you only need to specify a default database when using one type of client (e.g. mysql CLI, or PHP Data Objects), or do you need it to be for all clients? Do you need/want to override any default schema specified by the client on connecting? Do you want to disable changing of the default schema after one has been selected? – eggyalSep 14 '12 at 14:40