当前位置:硬件测评 > MySQL 连接数设置操作(Too many connections)及设置md5值的加密密码

MySQL 连接数设置操作(Too many connections)及设置md5值的加密密码

  • 发布:2023-09-29 04:04

在使用mysql时,发现连接数超标了~~~~

[root@linux-node1 ~]# mysql -ulance -h 192.168.1.17 -p
输入密码:
错误1040(08004):连接过多

解决办法,这也是centos7下修改mysql连接数的方法:
1)临时修改
MariaDB [(none)]>显示“max_connections”之类的变量;
+--- -- ------------+--------+
|变量名 |值|
+----------------+------+
|最大连接数 | 214 |
+-----------------+-------+
1 行(0.00 秒)
MariaDB [(无)]> 设置全局 max_connections=1000;
查询正常,0 行受影响(0.00 秒)
MariaDB [(none)]> 显示“max_connections”等变量;
+---------------- -+--------+
|变量名 |值 |
+---- -------------+-------+
|最大连接数 | 1000 |
+---------------- -+-------+
1 行一组(0.00 秒)

2)永久修改:
配置/etc/my.cnf
[mysqld] 新增一行,参数如下:
max_connections=1000
重启mariadb服务,查看最大连接数再次查看mariadb数据库的连接数,可以看到最大连接数是214,而不是我们设置的1000。
MariaDB [(none)]> 显示“max_connections”等变量;
+----------------+------+
|变量名 |价值|
+-----------------+------+
|最大连接数 | 214 | 214
+--- ----------------+-------+
这是因为 mariadb 对打开文件的数量有默认限制。您可以通过配置 /usr/lib/systemd/system/mariadb.service 来增加打开文件的数量。

配置 /usr/lib/systemd/system/mariadb.service
[Service] 添加两个新行,其中包含以下参数:
LimitNOFILE=10000
LimitNPROC=10000

重新加载系统服务并重启mariadb服务
systemctl --system daemon-reload
systemctl restart mariadb.service

再次查看mariadb数据库的最大连接数,可以看到最大连接数已经是1000
MariaDB [(none)]> show 'max_connections'等变量;
+--------- --------+--------+
|变量名 |价值|
+----------------+--- ----+
|最大连接数 | 1000 | 1000
+----------------+------+

================================================== =================================
mysql设置32位md5值的密文密码

如下,设置admin用户的密码为“123!@#ad”
mysql>从admin_user中选择*;
+----+----------+-------------------------------- - ----------------------------------+-------------- ------+---------------------+
|编号 |用户名 |密码 |创建时间|更新时间 |
+----+----------------+---------------------------- --- ----------------------------------+------------ ----------+---------------------+
| 1 |管理员 | 4ad597c11755c50d00457f4420365763 | 1538979880 | 1538979880 |
+----+----------------+---------------------------- --- ----------------------------------+------------ ----------+---------------------+
一组 1 行(0.00 秒)

mysql> 更新 admin_user 设置用户名 = 'admin',密码 = md5('123!@#ad') 其中 id = 1

mysql>从admin_user中选择*;+----+----------+-------------------------------- -----------------------------------+-------------- ------+---------------------+
|编号 |用户名 |密码 |创建时间|更新时间 |
+----+----------------+---------------------------- -----------------------------------+-------------- ------+---------------------+
| 1 |管理员 | 0fy866r8662a70d85632u90563212687 | 1541676212 | 1541676212 |
+----+----------------+---------------------------- -----------------------------------+-------------- ------+---------------------+
一组 1 行(0.00 秒)

相关文章