公告:魔扣目录网为广大站长提供免费收录网站服务,提交前请做好本站友链:【 网站目录:https://www.morko.net 】, 免友链快审服务(50元/站),

点击这里在线咨询客服
新站提交
  • 网站:51998
  • 待审:31
  • 小程序:12
  • 文章:1030137
  • 会员:747

让我们看看如何使用命令行选项与MySQL服务器建立连接,例如mysql或mysqldump这样的客户端。

为了使客户端程序能够连接到MySQL服务器,它必须使用正确的连接参数,例如服务器运行的主机名、MySQL帐户的用户名和密码。每个连接参数都有一个默认值,但在必要时可以使用在命令行或选项文件中指定的程序选项进行覆盖。

调用mysql

调用mysql而不指定任何显式连接参数的命令是−

mysql

登录后复制

由于没有参数选项,将应用默认值。

    默认主机名为localhost。在Unix上,它有特殊含义。

    默认用户名在Windows上是ODBC。在Unix上,是Unix上的登录名。

    没有发送密码,因为没有提供–password或-p。

    对于mysql,第一个参数被视为默认数据库的名称。由于没有这样的参数,因此mysql不选择任何默认数据库。

    Imvoke – 指定主机名、用户名和密码

    要明确指定主机名、用户名和密码,必须在命令行上提供适当的选项。如下所示:

    mysql --host=localhost --user=myname --password=password mydb
    mysql -h localhost -u myname -ppassword mydb

    登录后复制

    The password value is optional.

      If a –password or -p option is present, and a password value is mentioned, there shouldn’t be any space between –password= or -p and the password that follows it.

      If –password or -p doesn’t specify a password value, the client program prompts the user to enter the password. The password doesn’t get displayed when it is entered.

      Type of Connection

      Next step is for client programs to determine the type of connection that needs to be made. To ensure that the client makes a TCP/IP connection to the local server only, the –host or -h option is used to specify a host name with the value of 127.0.0.1 (instead of localhost). Instead of this, the IP address or name of the local server can also be provided. The transport protocol can be explicitly mentioned even for localhost using the –protocol=TCP option. Some examples have been shown below −

      mysql --host=127.0.0.1
      mysql --protocol=TCP

      登录后复制

      If connections need to be made to remote servers, then use TCP/IP. This command would help connect to the server that runs on remote.example.com using the default port number which is 3306. It has been shown below −

      mysql --host=remote.example.com

      登录后复制

      如果用户希望显示特定的端口号,需要提到 – -port 或 –P 选项 −

      mysql --host=remote.example.com --port=13306

      登录后复制

      以上就是使用命令选项连接到 MySQL 服务器的详细内容,更多请关注www.92cms.cn其它相关文章!

分享到:
标签:MySQL 命令 服务器 连接到 选项
用户无头像

网友整理

注册时间:

网站:5 个   小程序:0 个  文章:12 篇

  • 51998

    网站

  • 12

    小程序

  • 1030137

    文章

  • 747

    会员

赶快注册账号,推广您的网站吧!
最新入驻小程序

数独大挑战2018-06-03

数独一种数学游戏,玩家需要根据9

答题星2018-06-03

您可以通过答题星轻松地创建试卷

全阶人生考试2018-06-03

各种考试题,题库,初中,高中,大学四六

运动步数有氧达人2018-06-03

记录运动步数,积累氧气值。还可偷

每日养生app2018-06-03

每日养生,天天健康

体育训练成绩评定2018-06-03

通用课目体育训练成绩评定