MySQL 5.6 手冊 第三章 3.1 連接與斷開mysql連接

3.1 Connecting to and Disconnecting from the Server

3.1連接和斷開與服務器的連接


To connect to the server, you will usually need to provide a MySQL user name when you invoke mysql and, most likely, a password. If the server runs on a machine other than the one where you log in, you will also need to specify a host name. Contact your administrator to find out what connection parameters you should use to connect (that is, what host, user name, and password to use). Once you know the proper parameters, you should be able to connect like this:

爲了連接服務,你通常需要提供一個MySQL用戶名,可能還需要密碼。如果服務不在你所登陸的fu wu qish服務器上運行,你還需要指定服務器的主機名(或IP地址)。請與您的管理員聯繫,找出您應該使用哪些連接參數進行連接(即要使用的主機名,用戶名和密碼)。一旦你知道正確的參數,你應該可以這樣連接:

shell> mysql -h host -u user -pEnter password: ********

host and user represent the host name where your MySQL server is running and the user name of your MySQL account. Substitute appropriate values for your setup. The ******** represents your password; enter it when mysql displays the Enter password: prompt.

If that works, you should see some introductory information followed by a mysql> prompt:

host和user 象徵着MySQL 服務器的主機名和MySQL賬戶的用戶名。爲您的設置替換成適當的值。********代表你的密碼; 當mysql顯示Enter password:提示時輸入。

如果配置正確,你應該看到一些介紹性信息,然後是一個mysql>提示:

shell> mysql -h host -u user -pEnter password: ********
Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 25338 to server version: 5.6.38-standard

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql>

The mysql> prompt tells you that mysql is ready for you to enter SQL statements.

If you are logging in on the same machine that MySQL is running on, you can omit the host, and simply use the following:

mysql>提示 告訴你MySQL已經準備好讓您輸入SQL語句了。

假如MySQL運行的服務器與你登陸的設備是同一臺,你可以省略主機名設置,只需使用以下命令:

shell> mysql -u user -p

If, when you attempt to log in, you get an error message such as ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2), it means that the MySQL server daemon (Unix) or service (Windows) is not running. Consult the administrator or see the section of Chapter 2, Installing and Upgrading MySQL that is appropriate to your operating system.

For help with other problems often encountered when trying to log in, see Section B.5.2, “Common Errors When Using MySQL Programs”.

Some MySQL installations permit users to connect as the anonymous (unnamed) user to the server running on the local host. If this is the case on your machine, you should be able to connect to that server by invoking mysqlwithout any options:

如果您嘗試登錄時會收到錯誤消息(如 ERROR 2002(HY000)):無法通過套接字'/tmp/mysql.sock'(2)連接到本地MySQL服務器,這意味着MySQL服務器守護進程(Unix)或服務(Windows)未運行。請諮詢管理員或參閱 第2章適用於您的操作系統的安裝和升級MySQL部分。

有關嘗試登錄時經常遇到的其他問題的幫助,請參見第B.5.2節“使用MySQL程序時的常見錯誤”

一些MySQL安裝允許用戶作爲匿名(未命名)用戶連接到在本地主機上運行的服務器。如果您的機器是這種情況,您應該能夠通過調用mysql連接到該服務器,而不需要任何選項:

shell> mysql

After you have connected successfully, you can disconnect any time by typing QUIT (or \q) at the mysql> prompt:

連接成功後,您可以通過在提示符下鍵入QUIT(或\q)斷開連接mysql>

mysql> QUIT
Bye

On Unix, you can also disconnect by pressing Control+D.

Most examples in the following sections assume that you are connected to the server. They indicate this by themysql> prompt.

在Unix上,也可以通過按Control + D斷開連接。

以下部分中的大多數示例假定您已連接到服務器。他們通過mysql>提示來表示這一點 。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章