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不选择任何默认数据库。

    Remove.bg
    Remove.bg

    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

相关专题

更多
Golang 性能分析与pprof调优实战
Golang 性能分析与pprof调优实战

本专题系统讲解 Golang 应用的性能分析与调优方法,重点覆盖 pprof 的使用方式,包括 CPU、内存、阻塞与 goroutine 分析,火焰图解读,常见性能瓶颈定位思路,以及在真实项目中进行针对性优化的实践技巧。通过案例讲解,帮助开发者掌握 用数据驱动的方式持续提升 Go 程序性能与稳定性。

9

2026.01.22

html编辑相关教程合集
html编辑相关教程合集

本专题整合了html编辑相关教程合集,阅读专题下面的文章了解更多详细内容。

56

2026.01.21

三角洲入口地址合集
三角洲入口地址合集

本专题整合了三角洲入口地址合集,阅读专题下面的文章了解更多详细内容。

30

2026.01.21

AO3中文版入口地址大全
AO3中文版入口地址大全

本专题整合了AO3中文版入口地址大全,阅读专题下面的的文章了解更多详细内容。

396

2026.01.21

妖精漫画入口地址合集
妖精漫画入口地址合集

本专题整合了妖精漫画入口地址合集,阅读专题下面的文章了解更多详细内容。

118

2026.01.21

java版本选择建议
java版本选择建议

本专题整合了java版本相关合集,阅读专题下面的文章了解更多详细内容。

3

2026.01.21

Java编译相关教程合集
Java编译相关教程合集

本专题整合了Java编译相关教程,阅读专题下面的文章了解更多详细内容。

16

2026.01.21

C++多线程相关合集
C++多线程相关合集

本专题整合了C++多线程相关教程,阅读专题下面的的文章了解更多详细内容。

11

2026.01.21

无人机驾驶证报考 uom民用无人机综合管理平台官网
无人机驾驶证报考 uom民用无人机综合管理平台官网

无人机驾驶证(CAAC执照)报考需年满16周岁,初中以上学历,身体健康(矫正视力1.0以上,无严重疾病),且无犯罪记录。个人需通过民航局授权的训练机构报名,经理论(法规、原理)、模拟飞行、实操(GPS/姿态模式)及地面站训练后考试合格,通常15-25天拿证。

50

2026.01.21

热门下载

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

精品课程

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

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