How to change the default database for one user in MySQL
9,665
In the user's home directory (e.g. ~username) create a file named .my.cnf, or add to the existing .my.cnf file a line like :
database=databasename-you-want-by-default
Here are the contents of a typical .my.cnf:
[client]
host=localhost
user=root
password=root
database=mygotodb
Related videos on Youtube
Author by
Yitzchak
Updated on September 18, 2022Comments
-
Yitzchak over 1 year
Though this might seem like a http://serverfault.com question at first glance I don't think it is.
I have a mysql database on a server at work. Every time I log in to execute a query, I have to manually select the one database I want from the one database I have, which is a waste of time. Is there any way for me as an end user to set a default? -
Yitzchak over 12 yearsDoes the file have to be owned by mysql or can I just write it up myself?
-
Ram over 12 yearsshould be owned by the user, but so long as the user has read permissions that will suffice
-
AtliB over 2 yearsI was able to use just [client] database=mygotodb (that is, skipped the host/user/password)