다른 DBMS/MySQL&MariaDB
시스템 변수 변경방법
취미툰
2020. 12. 8. 15:39
반응형
오라클의 파라미터와 같이 DB의 시스템적인 설정들을 관리할 수 있습니다.
동적변수와 정적변수가 있습니다. 정적변수는 재기동을 해야 적용되는 변수이고 동적변수는
바로 적용되는 변수입니다.
2가지 방법으로 설정을 변경할 수 있습니다.
1.my.cnf에 매뉴얼하게 변수 입력 후 재기동
- 영구적으로 변경할 필요가 있을 때 사용(정적변수)
2.명령어로 수행
- 재기동필요는 없지만 재기동할 시 원래 값으로 돌아옴(동적변수)
테스트를 통해 값을 실제로 변경해보고 변경값을 확인해보겠습니다.
실행 DB : Mysql 8.0.22
1.my.cnf에 적용
목표 : max_connections=200으로 변경
--작업전 변수값 확인
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 151 |
+-----------------+-------+
1 row in set (0.00 sec)
--my.cnf 변경
[root@ysbae mysql]# cat /etc/my.cnf
[mysqld]
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
datadir=/data/mysql
socket=/data/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
max_connections=200
--DB 재기동
[root@ysbae mysql]# systemctl stop mysql.server
[root@ysbae mysql]# systemctl start mysql.server
--확인
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 200 |
+-----------------+-------+
1 row in set (0.00 sec)
100에서 200으로 변경되었음.
2.명령어로 변경
--확인
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 200 |
+-----------------+-------+
1 row in set (0.00 sec)
--변수 변경
mysql> set global max_connections=150;
Query OK, 0 rows affected (0.00 sec)
--변경값 확인
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 150 |
+-----------------+-------+
1 row in set (0.01 sec)
--DB 재기동
[root@ysbae mysql]# systemctl stop mysql.server
[root@ysbae mysql]# systemctl start mysql.server
--변수 확인
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 200 |
+-----------------+-------+
1 row in set (0.01 sec)
재기동시 my.cnf에 적용했던 값으로 되돌아감
다른변수를 적용후 재기동해보겠습니다.
--적용전 확인
mysql> show variables like 'max_connect_errors';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| max_connect_errors | 100 |
+--------------------+-------+
1 row in set (0.00 sec)
--적용
mysql> set global max_connect_errors=150;
Query OK, 0 rows affected (0.00 sec)
--적용된것 확인
mysql> show variables like 'max_connect_errors';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| max_connect_errors | 150 |
+--------------------+-------+
1 row in set (0.00 sec)
--재기동
[root@ysbae mysql]# systemctl stop mysql.server
[root@ysbae mysql]# systemctl start mysql.server
--값 확인
mysql> show variables like 'max_connect_errors';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| max_connect_errors | 100 |
+--------------------+-------+
1 row in set (0.01 sec)
ㅁ마찬가지로 원래의 변수 값으로 돌아가는 것을 확인할 수 있습니다.
변수에 따라서 Local 변수와 Global변수가 나눠져 있을 수 있습니다.
그에 따라 명령어가 차이가 있습니다.
local변수의 경우
set session ~
global 변수의 경우
set global ~
반응형