Connecting to a MySQL Server


shell> mysql [-h host] [-u user_name] [-p] [db_name]



Connections to a local MySQL server with the mysql command-line client are easy to make. Simply run mysql, providing these optional arguments:

  • -h Specify the host to which you want to connect. If you omit the -h option, mysql attempts to connect to a server on the local machine.

  • -u Specify the user you want to connect as. If you do not specify a -u option, mysql uses your Unix username to attempt to authenticate to MySQL.

  • -p Tell mysql to prompt you for a password. You can create accounts without passwords or specify the password to use as an argument on the command line. Neither approach is recommended because both significantly compromise the security of your MySQL accounts and installations.

  • database_name The name of the database on which you want to operate. If you don't specify this on connection or want to change it later, use the USE command, as in USE database_name;.

Other arguments can be specified to change how mysql behaves or to where it attempts to connect. Run mysql -? to see a complete list of possible arguments.

If you are unfamiliar with user accounts, see Chapter 6, "User Management and Security," for more information.



MySQL Phrasebook. Essential Code and Commands
MySQL Phrasebook
ISBN: 0672328399
EAN: 2147483647
Year: 2003
Pages: 130

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net