您的位置:首页 > 数据库 > MySQL

mysql 连接

2017-03-25 01:27 190 查看

##mysql 连接:

unix系统上,mysql的登陆方式有两种,分别是socket和tcp/ip方式登陆。

mysql登陆的时候,指定参数-h,会使用tcp/ip的方式连接,如果没有指定端口的话,默认是使用3306端口

当mysql登陆时,同时指定-h和-S,mysql会默认使用tcp/ip的方式连接。默认情况下访问3306端口。

在生产环境使用 :mysql -uroot -p -h<本机ip> 可能会失败

hosts 配置文件是用来把主机名字映射到IP地址的方法

vim /etc/hosts –hosts文件 有没有 关于 localhost 127.0.0.1

mysql>select * from mysql.user where User=’root’\G

– 可以查看到 有没有关于 本机ip的授权 root@’172.17.194.166’

登陆mysql 查看连接:

mysql> desc information_schema.processlist;

+———+———————+——+—–+———+——-+

| Field | Type | Null | Key | Default | Extra |

+———+———————+——+—–+———+——-+

| ID | bigint(21) unsigned | NO | | 0 | |

| USER | varchar(16) | NO | | | |

| HOST | varchar(64) | NO | | | |

| DB | varchar(64) | YES | | NULL | |

| COMMAND | varchar(16) | NO | | | |

| TIME | int(7) | NO | | 0 | |

| STATE | varchar(64) | YES | | NULL | |

| INFO | longtext | YES | | NULL | |

+———+———————+——+—–+———+——-+

8 rows in set (0.01 sec)

mysql> select * from information_schema.processlist where user=’mycat’;

与max_connections有关的特性

mysql> show variables like ‘%connect%’;

+———————————————–+—————–+

| Variable_name | Value |

+———————————————–+—————–+

| character_set_connection | utf8 |

| collation_connection | utf8_general_ci |

| connect_timeout | 10 |

| disconnect_on_expired_password | ON |

| init_connect | |

| max_connect_errors | 100 |

| max_connections | 2000 |

| max_user_connections | 0 |

| performance_schema_session_connect_attrs_size | 512 |

+———————————————–+—————–+

9 rows in set (0.00 sec)

MySQL无论如何都会保留一个用于管理员(SUPER)登陆的连接,用于管理员连接数据库进行维护操作,即使当前连接数已经达到了max_connections。因此MySQL的实际最大可连接数为max_connections+1;

这个参数实际起作用的最大值(实际最大可连接数)为16384,即该参数最大值不能超过16384,即使超过也以16384为准;

如何设置 max_connections

vim /etc/my.cnf

max_connections=2000

实时(临时)修改此参数的值

mysql> SELECT @@MAX_CONNECTIONS ; / select @@max_connections; / SELECT @@MAX_CONNECTIONS AS ‘Max Connections’;

+——————-+

| @@MAX_CONNECTIONS |

+——————-+

| 2000 |

+——————-+

1 row in set (0.00 sec)

mysql> set GLOBAL max_connections=2500;

Query OK, 0 rows affected (0.02 sec)

mysql> SELECT @@MAX_CONNECTIONS ;

+——————-+

| @@MAX_CONNECTIONS |

+——————-+

| 2500 |

+——————-+

1 row in set (0.00 sec)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql mysql连接