使用命令选项连接到 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 1二7.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=1两7.0.0.1
mysql --protocol=TCP
登录后复造

If connections need to be made to remote servers, then use TCP/IP. This co妹妹and 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 任事器的具体形式,更多请存眷萤水红IT仄台此外相闭文章!

点赞(38) 打赏

评论列表 共有 0 条评论

暂无评论

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部