Connecting to a MySQL server often involves providing hostnames, usernames and passwords. Use a .my.cnf configuration file to provide defaults that simplify working with a MySQL server. 

Providing a default password reduces security. Take effort to make sure that the password cannot be read by other users on the system. If the server runs locally, use credentials that are only allowed to connect locally.

Open or create the .my.cnf file in your home-directory.

% nano ~/.my.cnf

Provide default connection options. Mix and match the lines as you wish.

[client]
user=username
host=localhost
password=p455w0rd 
database=databasename

Save the file. Modify the file permissions such that only the owner may write and read the file.

% chmod 700 ~/.my.cnf

It is possible to omit the password line in the configuration file and provide it explicitly on the command line:

% mysql -p