When you want to connect with a client program to a MySQL server that is listening to different network interfaces than those compiled into your client, you can use one of the following methods:
--host=host_name --port=port_number
to connect
via TCP/IP to a remote host, or with --host=localhost --socket=file_name
to connect to a local host via a Unix socket or a Windows named pipe.
--protocol=tcp
to connect
via TCP/IP, --protocol=socket
to connect via a Unix socket,
--protocol=pipe
to connect via a named pipe, or
--protocol=memory
to connect via shared memory. For TCP/IP
connections, you may also need to specify --host
and --port
options. For the other types of connections, you may need to specify
a --socket
option to specify a socket or named pipe name, or a
--shared-memory-base-name
option to specify the shared memory name.
MYSQL_UNIX_PORT
and MYSQL_TCP_PORT
environment variables
to point to the Unix socket and TCP/IP port before you start your clients.
If you normally use a specific socket or port, you can place commands
to set these environment variables in your `.login' file so that they
apply each time you log in.
See section F Environment Variables.
[client]
group of
an option file. Foe example, you can use `C:\my.cnf' on Windows, or
the `.my.cnf' file in your home directory on Unix. See section 4.1.2 `my.cnf' Option Files.
mysql_real_connect()
call. You can also have the program read
option files by calling mysql_options()
.
See section 9.1.3 C API Function Descriptions.
DBD::mysql
module, you can read the options
from the MySQL option files. For example:
$dsn = "DBI:mysql:test;mysql_read_default_group=client;" . "mysql_read_default_file=/usr/local/mysql/data/my.cnf"; $dbh = DBI->connect($dsn, $user, $password);See section 9.5.2 The
DBI
Interface.