728x90
반응형

**************************************
MySQL 프로시저(procedure), 함수(function) 생성/실행 권한 주기



 MySQL 일반 User로서는 프로시저와 함수를 만들거나 실행할 수 없는 것이 기본 설정이다.
필요에 따라 가능하게 바꾸어 주자.

1. 프로시저 및 함수 생성 권한 확인

SHOW VARIABLES LIKE '%log_bin_trust_function_creators%';

#기본값은 "OFF"



2, 프로시저 및 함수 생성 권한 주기

SET GLOBAL log_bin_trust_function_creators = 1;


3. 확인

SELECT * FROM information_schema.ROUTINES;


4. 실행 권한 부여

grant execute on function `db명`.`함수명` to '사용자명'@'localhost';
flush privileges;

 

728x90
SMALL
Posted by gromet
728x90
반응형

Postfix + header_checks in MySQL

 
In this tip I will describe how to implement Postfix header_checks along with MySQL . No blablabla....let's get straight to the point. For everything to work it is necessary to have MySQL installed. On Debian like distributions, type the following command to install the MySQL server: # apt-get install mysql-server-5.5 After that, follow the installation steps that will be described on the screen. Log in as ROOT in your MySQL and create the database "postfix", or any other name that is easy to identify: # mysql -u root -p CREATE DATABASE postfix; Enter the postfix database to be able to create the table inside it: use postfix;

Now create the header_checks table with the following command:

CREATE TABLE `header_checks` (
  `hc_id` int(11) NOT NULL AUTO_INCREMENT,
  `rule` varchar(255) NOT NULL,
  `action` varchar(255) NOT NULL,
  PRIMARY KEY ( `hc_id`),
  KEY `rule` (`rule`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8

Postfix preparation

I believe that you must already have Postfix installed on your server, there are already several articles dealing with its installation.

We will now create the configuration file for communicating with MySQL:

# vi /etc/postfix/header_checks.cf

Put this content inside the file we are editing:
user = YOUR_BANK_USER_postfix
password = YOUR_BANK_PASSWORD_postfix
hosts = IP_or_YOUR_Server_NAME
dbname = DATABASE_NAME_postfix
query = SELECT action FROM header_checks WHERE '%s' REGEXP rule LIMIT 0.1
Next step is to edit the configuration in the /etc/postfix/main.cf file , if you don't already have the line below, add it:
header_checks = mysql:/etc/postfix/header_checks.cf
With these steps completed, we just have to restart postfix and populate the header_checks table in MySQL, which I will show the correct syntax below.

# /etc/init.d/postfix restart

Creating check rules in MySQL

Here we don't have many secrets, what gave me more work was finding the correct syntax to write the rule, but I'll save you this hard work and pass the correct syntax the way I'm using it on my servers.

Access MYSQL:

# mysql -u root -p

use postfix;

INSERT INTO header_checks (`hc_id`, `rule`, `action`) VALUES (NULL, '^From:(.*)domain.com.br', 'DISCARD #SPAM Domain Detected');


Note that the syntax for REGEXP used by header_checks follows the following pattern:

^From:(.*)dominio.com.br

I particularly use this rule to block domains that usually send SPAMs, but we can use it, for example, to block messages with certain subjects, in this case the rule would look like this:

^Subject:(.*)PROPAGANDA

Well folks, that's it...

I hope the subject has been addressed in a clear and objective way.

Hugs.

Measure
Measure
 
 
728x90
SMALL
Posted by gromet

2021. 11. 10. 18:55 WorkHolic

MySQL Proxy

728x90
반응형

https://www.google.com/imgres?imgurl=https%3A%2F%2Fcodar.club%2Fimages%2Fblog%2Ffcf589883c9ce52e921caaea5443b525.jpg&imgrefurl=https%3A%2F%2Flaptrinhx.com%2Fhow-to-use-haproxy-to-proxy-mysql-master-slave-replication-3214137223%2F&tbnid=-LRzCkXXxv8JlM&vet=12ahUKEwjnzLmJjo30AhUgxIsBHWdSDYsQMyhDegQIARBU..i&docid=_CteLUqqKoLDLM&w=501&h=264&q=making%20mysql%20proxy&ved=2ahUKEwjnzLmJjo30AhUgxIsBHWdSDYsQMyhDegQIARBU

서버로 연결되는 query를 수정하여 원치않는 union과 같은 command를 차단하고 싶다.
SQL Injection을 방지하고 싶다. 프로그램 개발자에게 구걸하지 않고.
MySQL용 Proxy를 사용하면 가능할 것 같다.

찾아보니 아래와 같은 MySQL Proxy 사용이 가능했고,
query rewirte외에도 load balancing, 읽기 분산등 사용 가능한 것이 많다.

검토하고 적용 테스트해 해 볼 예정이다.

1. MySQL Proxy
https://downloads.mysql.com/docs/mysql-proxy-en.pdf

2. ProxySQL
https://proxysql.com

 

ProxySQL - A High Performance Open Source MySQL Proxy

ProxySQL is a MySQL protocol proxy supporting Amazon Aurora, RDS, ClickHouse, Galera, Group Replication, MariaDB Server, NDB, Percona Server and more...

proxysql.com

 

3. HAProxy
   HAProxy를 이용하는 것도 가능하다고 하는데 사용례등을 좀 더 검토해 봐야겠다.

#mysql #proxy

728x90
SMALL
Posted by gromet
728x90
반응형

 

 

 

--

Photo by Sasun Bughdaryan on Unsplash

 

MYSQL에서 user의 비밀번호는 PASSWORD()를 사용하여 암호화하고 저장한다.
간혹 혹은 대부분, 로그인 정보를 다룰 때 암호의 저장 방법에도 사용한다.
(MYSQL 공식적으로는 사용하지 말라고 한다.)

고객님으로부터 질문을 받았다.
PASSWORD()는 어떤 해싱 알고리즘을 사용하나요?

그래서 찾아봤다.

MYSQL PASSWORD() 해싱 알고리즘 = SHA1(SHA1(password))

 

참고한 사이트 

https://blog.pythian.com/hashing-algorithm-in-mysql-password-2/

 

Hashing Algorithm in MySQL PASSWORD() | Official Pythian® Blog

Recently we had a question from a customer: what is the hashing algorithm implemented in PASSWORD() ? The manual doesn't give a straight answer in any of

blog.pythian.com

에서 보면
필자도 고객으로부터 질문을 받고 예전 관련 자료를 확인하고 직접 적용하여 확인해 보았다.

 

예, mysql.user.password에 SHA1 (SHA1 (password))로 저장하고 있음을 확인했습니다.
또한 이 게시물이 MySQL이 PASSWORD()를 구현하는 방법을 이해하는데 유용하기를 바랍니다.

 

#mysql #password() #해싱 #알고리즘 #hashing #algorithm 

--

 

 

 

728x90
SMALL
Posted by gromet
728x90
반응형

 

 

 

--

Image by dschap from Pixabay

 

데이터베이스 테이블 중 내용을 삭제하고 싶은 테이블이 있어서 trucate를 했더니 오류가 나면서 안된다.

 

SQL 오류 (1701): Cannot truncate a table referenced in a foreign key constraint

 

foreign key를 통해서 서로 연결되어 있는 테이블은 단독으로 삭제가 되지 않는다.

 

delete from table;

 

delete 명령으로 삭제를 했더니, 관련된 모든 테이블의 내용을 모두 삭제해 버렸다.
그 테이블의 내용만 지우고 싶었는데...

삭제 방법은 임시로 foreign key를 사용하지 않는다고 선언했다가, 다시 사용하는 것으로 선언하면 된다.

 

> set FOREIGN_KEY_CHECKS = 0;
Query OK, 0 rows affected (0.000 sec)

> truncate table_name;
Query OK, 0 rows affected (0.351 sec)

> set FOREIGN_KEY_CHECKS = 1;
Query OK, 0 rows affected (0.000 sec)

 

#mysql #truncate #foreign_key

--

 

 

 

728x90
SMALL
Posted by gromet
이전버튼 1 이전버튼

블로그 이미지
나는 운이 좋은 사람이다 나는 나날이 점점 더 좋아진다 내가 하는 선택과 행동은 반드시 성공으로 이어진다 내게는 인내력과 지속력이 있다 네게는 좋은것들만 모여든다
gromet

공지사항

Yesterday
Today
Total
반응형

달력

 « |  » 2024.6
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

160x600