ITPub博客

首页 > 数据库 > MySQL > Connecting to the MySQL Server

Connecting to the MySQL Server

原创 MySQL 作者:孤竹星 时间:2015-04-16 14:51:20 0 删除 编辑

客户端程序连接MySql服务

1. 不指定连接参数

因为没有指定参数,将使用默认值
语法:shell> mysql
默认主机名为:localhost
[root@root ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.6.24 MySQL Community Server (GPL)


Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> 

2. 指定主机名和用户名和密码

语法:
shell> mysql --host=localhost --user=myname --password=mypass mydb
shell> mysql -h localhost -u myname -pmypass mydb

host:主机名  user:登录的用户 password:密码 mydb:访问的数据库


[root@qingmeng001 ~]# mysql --host=localhost --user=chenwx --password=chenwx mysql
Warning: Using a password on the command line interface can be insecure.
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 29
Server version: 5.6.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

[root@qingmeng001 ~]# mysql -h localhost -u chenwx -pchenwx mysql
Warning: Using a password on the command line interface can be insecure.
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 30
Server version: 5.6.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

note:使用-p或 --password指定密码,在-p或-password后不能有空格

3.避免因安全问题,指定-p或-password选项不直接跟密码

语法:
shell> mysql --host=localhost --user=myname --password mydb
shell> mysql -h localhost -u myname -p mydb

[root@qingmeng001 ~]# mysql --host=localhost --user=chenwx --password mysql
Enter password:    --输入密码,不显示输入内容及输入个数
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 31
Server version: 5.6.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

4.指定IP和协议

语法:
shell> mysql --host=127.0.0.1
shell> mysql --protocol=TCP
--protocol={TCP|SOCKET|PIPE|MEMORY}

在一些unix系统中需要强制指定TCP/IP,否则指定的端口号将呗忽略

5. 配置ipv6

--host=::1.

6. 使用TCP/IP连接到远程服务器

语法:
shell> mysql --host=remote.example.com
默认端口:3306

7.指定端口选项--port -P

语法:
shell> mysql --host=remote.example.com --port=13306

8. windows使用named-pipe连接

语法:
--pipe
--protocol=PIPE


--protocol                
Value            Connection Protocol                                                    Permissible Operating  Systems
TCP                 TCP/IPconnection to local or remote server                                All
SOCKET            Unix socket file connection to local server Unix                          only
PIPE                Named-pipe connection to local or remote serverWindows         only
MEMORY          Shared-memory connection to local serverWindows                     only

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/28282660/viewspace-1579988/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: linux下mysql卸载
请登录后发表评论 登录
全部评论

注册时间:2013-01-22

  • 博文量
    96
  • 访问量
    298368