Hey Slap: How Do I Define My Own MySQL Prompt?

Posted on in Software

Someone looked over my shoulder the other day and was blown away by my MySQL client prompt.

(slap@localhost) [slaptijack]>

The boring default client just acknowledges that you are using MySQL and nothing more. This prompt indicates your username, the server you are working on, and the database you are working in. Without further ado, here's how to implement your own MySQL Prompt.

  1. Create .my.cnf in your home directory. Before I edit a new file, I usually touch it and give it the proper permissions (if different than what is set with umask). In your home directory, simply issue touch .my.cnf.

  2. Add the prompt definition to your .my.cnf file Using your favorite text editor add the following two lines to your .my.cnf file.

    [mysql]
    prompt=(\\u@\\h) [\\d]>\\_
    
    </p>
    

That should be it. Give it a test run and let me know if you have any problems.

Further Reading:

My Bookshelf

Reading Now

Other Stuff