How to avoid using db_name every time you start mysql

Each time I run mysql, the first query 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 any way to do this?

EDIT: I am connecting to mysql from the command line.

+4
source share
3 answers

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

database=db_name 
+5
source

Just use

 mysql -uuser -ppassword databasename 
+1
source

You can specify the database when connecting:

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

or directly:

 mysql my_db_name 
0
source

All Articles