使用命令选项连接到 MySQL 服务器
来源:tutorialspoint
时间:2023-08-28 17:50:04 297浏览 收藏
珍惜时间,勤奋学习!今天给大家带来《使用命令选项连接到 MySQL 服务器》,正文内容主要涉及到等等,如果你正在学习数据库,或者是对数据库有疑问,欢迎大家关注我!后面我会持续更新相关内容的,希望都能帮到正在学习的大家!
让我们看看如何使用命令行选项与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 服务器》的详细内容,更多关于的资料请关注golang学习网公众号!
-
501 收藏
-
501 收藏
-
501 收藏
-
501 收藏
-
501 收藏
-
409 收藏
-
113 收藏
-
161 收藏
-
422 收藏
-
451 收藏
-
215 收藏
-
400 收藏
-
175 收藏
-
338 收藏
-
331 收藏
-
264 收藏
-
261 收藏
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 立即学习 542次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 立即学习 508次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 立即学习 497次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 立即学习 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 立即学习 484次学习