Easy MySQL server login trick

December 15, 2006

I just discovered a new MySQL tip today that I sub-consciously wanted. A way to type one command and be logged into MySQL server when I was on the production machine. Here is how you do it:

Create a file .my.cnf in your home directory. Put the following entry into it:

[mysql]
user=user
password=pass

Then create a file in /usr/local/bin called db or whatever, and put this in it:

#!/bin/bash
mysql db_name

Now from anywhere in the terminal you can type . db and automatically have a mysql prompt. Lovely!

Advertisements

So in the past two months I have migrated between three servers. Including my development machine, I have done the same inital setups to get an application going four times in the past 6 months. I always look at bookmarked pages in the MySQL mannual to set it all up. So here I am again doing the setup and documenting, the simple, but often used commands to setup a new application database.

mysql> create database money_maker;
mysql> GRANT ALL PRIVILEGES ON money_maker.* TO 'bam'@'localhost' IDENTIFIED BY 'passw0rd'; 

That’s it. Move on.