mysql 连接

##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

  1. vim /etc/my.cnf
    max_connections=2000
  2. 实时(临时)修改此参数的值
    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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值