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

王林
发布: 2023-09-02 08:21:03
转载
1159人浏览过

使用命令选项连接到 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 服务器的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:tutorialspoint网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

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