4

Every time I start mysql, first query that I type is "use my_db_name" where my_db_name is the name of the database that I always use. I would like mysql to use my_db_name by default. Is there a way we can do that?

EDIT: I am connecting to mysql from command line.

4
  • How are you connecting to mysql? Commented May 14, 2011 at 8:19
  • Hi Darin, I am connecting to mysql from command line. Commented May 14, 2011 at 8:20
  • you can define the database name while connecting to server Commented May 14, 2011 at 8:22
  • while connecting to mysql you can pass the name of database as an argument i think. Commented May 14, 2011 at 8:22

3 Answers 3

5

In the options file (on windows my.ini, on linux my.cnf), in the Client section add the following:

database=db_name
Sign up to request clarification or add additional context in comments.

1 Comment

Cool. That's what I was looking for. We need to put this directive in [mysql] section.
1

Just use

mysql -uuser -ppassword databasename

1 Comment

Ok. That is useful. However, I don't type "-uuser -ppassword" part since I have put username/password in /etc/my.conf. So, "mysql databasename" does the job for me. Further I can alias "mysql" to "mysql databasename" and then just happily type "mysql" on console.
0

You could specify the database when connecting:

mysql --user=root --password=secret --database=my_db_name

or directly:

mysql my_db_name

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.