Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4262945
  • 博文数量: 1148
  • 博客积分: 25453
  • 博客等级: 上将
  • 技术积分: 11949
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-06 21:14
文章分类

全部博文(1148)

文章存档

2012年(15)

2011年(1078)

2010年(58)

分类: Mysql/postgreSQL

2011-08-04 09:03:44

本章主要讲述mysql支持的几种连接方式,也将对这几种方式进行操作演示

补充一点,mysql启动没有

  1. mysql启动没有
  2. ywx@ywx:~$ cd /opt/mysql5151/
  3. ywx@ywx:/opt/mysql5151$ ./bin/mysqld_safe --defaults-file=./my.cnf --user=ywx &
  4. [1] 8333
  5. ywx@ywx:/opt/mysql5151$ 110804 08:40:52 mysqld_safe Logging to

  6. '/opt/mysql5151/data/ywx.err'.
  7. 110804 08:40:52 mysqld_safe Starting mysqld daemon with databases from /opt/mysql5151/data

  8. ywx@ywx:/opt/mysql5151$ ./bin/mysqladmin --defaults-file=./my.cnf ping
  9. mysqld is alive


1. 首先看看mysql支持的连接协议
   在linux OS上,只支持 TCP/IP 和 socket 协议
   TCP/IP :  支持所有的OS
   socket : 只支持 本地连接,只支持类unix linux OS


 几种协议的具体介绍




linux,下面将对 TCP/IP 和 socket 协议进行操作


首先启动 mysql 服务

ywx@ywx:/opt/mysql5151$./bin/mysqld_safe --defaults-file=./my.cnf --user=ywx &

1. 对 socket协议进行操作

  1. cd /tmp/  下
  2. 查看内容,注意有个 mysql.sock,这就是我们需要连接的文件

ywx@ywx:/tmp$ ls
keyring-qBd4di  pulse-PKdhtXMmr18n  VMwareDnD
mysql.sock      pulse-vW0CAOZ7PouR  vmware-root
orbit-gdm       ssh-pogBWO1710      vmware-ywx
orbit-ywx       virtual-ywx.E2YEf7

   3.操作
  1. ywx@ywx:/tmp$ /opt/mysql5151/bin/mysql --defaults-file=/opt/mysql5151/my.cnf -S
  2. ./mysql.sock --protocol=xx //敲入一个随便的,提示只能有4中连接方式
  3. Unknown option to protocol: xx
  4. Alternatives are: 'TCP','SOCKET','PIPE','MEMORY'
  5. ywx@ywx:/tmp$

  6. ywx@ywx:/tmp$ /opt/mysql5151/bin/mysql --defaults-file=/opt/mysql5151/my.cnf -S
  7. ./mysql.sock --protocol=socket 敲入socket,成功连接
  8. Welcome to the MySQL monitor. Commands end with ; or \g.
  9. Your MySQL connection id is 3
  10. Server version: 5.1.51bbk Source distribution

  11. Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
  12. This software comes with ABSOLUTELY NO WARRANTY. This is free software,
  13. and you are welcome to modify and redistribute it under the GPL v2 license

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

  15. mysql>

 2. tcp连接方式
 
  1. ywx@ywx:/tmp$ /opt/mysql5151/bin/mysql --defaults-file=/opt/mysql5151/my.cnf -h localhost
  2. --protocol=tcp
  3. Welcome to the MySQL monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 4
  5. Server version: 5.1.51bbk Source distribution

  6. Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
  7. This software comes with ABSOLUTELY NO WARRANTY. This is free software,
  8. and you are welcome to modify and redistribute it under the GPL v2 license

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

  10. mysql>

 远程tcp连接方式
  1. -u[用户名] -p(密码) -h [主机名,也可以是IP地址] -P [端口号]
  2. -u root -p -h localhost -P 3306

  3. ywx@ywx:/opt/mysql5151$ ./bin/mysql --defaults-file=./my.cnf -u root -p -h localhost -P 3306
  4. Enter password:
  5. Welcome to the MySQL monitor. Commands end with ; or \g.
  6. Your MySQL connection id is 13
  7. Server version: 5.1.51bbk Source distribution

  8. Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
  9. This software comes with ABSOLUTELY NO WARRANTY. This is free software,
  10. and you are welcome to modify and redistribute it under the GPL v2 license

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

  12. mysql>


阅读(833) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~