Detailed description of the connection method between MySQL and the client

Source: Internet
Author: User

This article demonstrates how to use the mysql client program to connect to the database server. Mysql is an interactive program that allows you to connect to a MySQL server, run the query, and view the results. Mysql can be used in the batch mode: You put the query in a file in advance and then tell the mysql execution file content. Both methods of using mysql are involved here.

To view a selection project table provided by mysql, call it using the -- help option:

Shell> mysql -- help

This chapter assumes that mysql has been installed on your machine and has a MySQL server that you can connect. If this is not true, contact your MySQL administrator. (If you are an administrator, you will need to consult other chapters in this manual .)

Establish and stop connections with the server

1. How to use a client to establish a connection

To connect to the server, activate the mysql program from the shell program (that is, from a UNIX prompt, or from the DOS console in Windows. The command is as follows:

Shell> mysql

Another example is to directly connect to a database:

Shell> mysql db_name

"$" Represents the shell prompt in this book. This is one of the standard UNIX prompts; the other is "#". In Windows, the prompt is similar to "c:> ".

2. The most common options for a client: Host, user, and password

To connect to the server, when you call mysql, you usually need to provide a MySQL user name and probably a password. If the server runs on a machine that you are not logged on to, you also need to specify the host name. Contact your administrator to find out what connection parameters you should use to connect (that is, the host, username and password used ). Once you know the correct parameters, you should be able to connect like this:

Shell> mysql-h host-u user-p

Enter password :********

* ******* Indicates your password. when mysql displays Enter password: prompt, Enter it.

At the beginning of learning MySQL, you may be worried about its security system, because it makes it difficult for you to do what you want. (You must obtain the permission to create and access the database. You must give your own name and password to connect to the database at any time .) However, after you enter and use your own records through the database, your views will change immediately. At this time, you will appreciate that MySQL has prevented others from spying (or worse, damage !) Your information.

The following describes the meaning of the options:

-H host_name (optional format: -- host = host_name)

The server host that you want to connect. This option can be omitted if the server runs on the same machine as mysql.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.