开发者

Default database for MySQL

Is there a way to allocate a d开发者_StackOverflowefault database to a specific user in MySQL so they don't need to specify the database name while making a query?


I think you need to revisit some concepts - as Lmwangi points out if you are connecting with mysql client then my.cnf can set it.

However, your use of the word query suggests that you are talking about connecting from some programming environment - in this case you will always need a connection object. To create connection object and in this case having default database to connect to will lead to no improvement (in terms of speed or simplicity). Efficiently managing your connection(s) might be interesting for you - but for this you should let us know exactly what is your environment.


If you use a database schema you don't need to specify the database name every time, but you need to select the database name.


The best thing to do would be to use a MySQL trigger on the connection. However, MySQL only accepts triggers for updates, deletes and inserts. A quick Google search yielded an interesting stored procedure alternative. Please see MySQL Logon trigger.


When you assign the permissions to every user group, you can also specify, at the same file, several things for that group, for example the database that users group need to use.

You can do this with a specification file, depending on the language you are working with, as a simple variable. Later, you only have to look for that variable to know which database you need to work with. But, I repeat, it depends on the language. The specification file can be an XML, phpspecs file, or anything like this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜