How do I log on to MySQL automatically?
Author: Deron Eriksson
Description: This tutorial describes how to log on to MySQL automatically.
Tutorial created using: Windows XP || MySQL 5.0.27


It is possible to configure MySQLW so that you can execute 'mysql' at the command prompt without needing to enter a name, password, or host. One way to do this is to edit the my.ini file within the directory where MySQL is installed. You can add a host, user, and password to either the [client] or [mysql] sections of the my.ini file. You can think of the client section as a global place to put this information for the various tools that ship with MySQL, and you can think of the [mysql] section as specific to only the 'mysql' tool.

my.ini file

Below is an example of adding a host, user, and password to the [client] section of my.ini.

modifying my.ini file

After doing this, we can now access mysqlW automatically without requiring a user, password, and host to log on.

accessing mysql via 'mysql' at command prompt

In addition to this, you can create a C:\my.ini file with a [client] section and the same user name, host, and password. This will also allow you to automatically log on to mysql. You can also create a C:\my.cnf file and do the same thing, but personally I'm not wild about this, because my version of Windows XP hides the .cnf extension even when I've directed XP to show all extensions. Apparently you can also put a my.ini file within your C:\WINDOWS directory, but personally I'm not wild about putting things in the actual Windows directory, so I'd recommend either the my.ini within the MySQL install directory, or the C:\my.ini file.