0

0

使用命令选项连接到 MySQL 服务器

王林

王林

发布时间:2023-09-02 08:21:03

|

1292人浏览过

|

来源于tutorialspoint

转载

使用命令选项连接到 mysql 服务器

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

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

调用mysql

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

mysql

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

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

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

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

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

    koolio.ai
    koolio.ai

    几分钟内把一个概念变成一个完整的播客

    下载

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

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
ip地址修改教程大全
ip地址修改教程大全

本专题整合了ip地址修改教程大全,阅读下面的文章自行寻找合适的解决教程。

86

2025.12.26

压缩文件加密教程汇总
压缩文件加密教程汇总

本专题整合了压缩文件加密教程,阅读专题下面的文章了解更多详细教程。

50

2025.12.26

wifi无ip分配
wifi无ip分配

本专题整合了wifi无ip分配相关教程,阅读专题下面的文章了解更多详细教程。

100

2025.12.26

漫蛙漫画入口网址
漫蛙漫画入口网址

本专题整合了漫蛙入口网址大全,阅读下面的文章领取更多入口。

293

2025.12.26

b站看视频入口合集
b站看视频入口合集

本专题整合了b站哔哩哔哩相关入口合集,阅读下面的文章查看更多入口。

589

2025.12.26

俄罗斯搜索引擎yandex入口汇总
俄罗斯搜索引擎yandex入口汇总

本专题整合了俄罗斯搜索引擎yandex相关入口合集,阅读下面的文章查看更多入口。

725

2025.12.26

虚拟号码教程汇总
虚拟号码教程汇总

本专题整合了虚拟号码接收验证码相关教程,阅读下面的文章了解更多详细操作。

63

2025.12.25

错误代码dns_probe_possible
错误代码dns_probe_possible

本专题整合了电脑无法打开网页显示错误代码dns_probe_possible解决方法,阅读专题下面的文章了解更多处理方案。

30

2025.12.25

网页undefined啥意思
网页undefined啥意思

本专题整合了undefined相关内容,阅读下面的文章了解更多详细内容。后续继续更新。

94

2025.12.25

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号