spacer
 
 
 
 
 
 
back spacer button
menu

Connect to MySQL

MySQL clients typically require that you specify the connection settings to connect to MySQL server: the host you want to use your username and password. For example, the mysql client can be started like this (optional arguments are in square brackets '[' and ']'):

shell> mysql [-h hostname] [-u user_name] [-pvotre_mot_de_passe]

Alternative forms of the options-h,-u and-p are - host = host_name, - user = user_name and - password = your_pass. Note that there is no space between the-p or - password = and the password following it.

Note: Specify a password on the command line is not safe! Any user on your server can discover your password by typing the command: ps auxww. Please see Option Files.

MySQL uses default values for each parameter missing from the command line:

  • The hostname is localhost.
  • The username is your default user name of UNIX.
  • No password is sent if-p is missing.

For example, for a Unix user joe, the following commands are equivalent:

shell> mysql-h localhost-u joe
shell> mysql-h localhost
shell> mysql-u joe
shell> mysql

Other MySQL clients behave similarly.

On UNIX, you can specify different default values to be used where you would establish the connection, so you do not have to enter them on the command line when you invoke a client program. This can be done in several ways:

  • You can specify the connection information in the [client] configuration file. My.cnf in your home folder. The section you are interested looks like this:
    [Guest]
    host = hostname
    user = user_name
    password = your_password

Using Option Files

You can specify connection parameters using environment variables. The host can be specified for mysql using MYSQL_HOST. The MySQL username can be specified using USER (for Windows). The password can be specified with MYSQL_PWD but this is unsafe. See the next section Environment Variables MySQL.

spacer
web hosting, web design Web Hosting Web Design templates AFFILIATE PROGRAM