데이터가 좀 지랄 같이(?) 많은 녀석이긴 한데


mysql> select count(*) from dht11;

+----------+

| count(*) |

+----------+

|    57186 |

+----------+

1 row in set (0.09 sec)


mysql> select count(*) from ph;

+----------+

| count(*) |

+----------+

|    57637 |

+----------+

1 row in set (0.17 sec) 


아무생각 없이 조인하고 조건식을 돌리니 8초.. ㄷㄷ

select * from dht11 as T,ph as P where T.created = P.created and DATE(T.created) >= '2018-12-20'; 

97 rows in set (8.12 sec)


날짜 쳐내고 조인하니 0.44초!

select * from 

(select * from dht11 where DATE(created) >= '2018-12-20' ) as T,

(select * from ph where DATE(created) >= '2018-12-20' ) as P 

WHERE T.created = P.created; 

98 rows in set (0.44 sec)



+
요건 DATE() 찾아 본다고 링크 추가

[링크 : https://code.i-harness.com/ko-kr/q/1c4e6a]

Posted by 구차니

걍 아이피 주면 될줄 알았는데 그건 dbname으로 인식하고

-h 옵션 뒤에 호스트 아이피나 도메인을 입력하면 된다.

$ mysql -u fooUser -p -h 44.55.66.77 

[링크 : https://support.rackspace.com/how-to/mysql-connect-to-your-database-remotely/]

Posted by 구차니

ubuntu 18.04 Desktop Edition 64biut에

원인불명으로 mysql이나 mariadb를 설치하고 service start를 해주는데

한참 있다가 죽어 버리고 에러 메시지를 보니

시작 timeout 걸렸다거나

정상적인 종료 라고 써있어서 검색을 해보니


웬지 apparmor라는 놈이 제 2의 selinux 같은 악의 축으로 등극할 삘?

아무튼 이걸 아래 명령을 통해 apparmor로 보호하지 않도록 하면 문제없이 실행된다.

$ sudo ln -s /etc/apparmor.d/usr/sbin/mysqld /etc/apparmor.d/disable/ 


[링크 : https://jimnong.tistory.com/758]

Posted by 구차니

한글로 된 내용을 저장하려고 했는데

"Warning: Incorrect string value:" 요런 에러 뿜뿜


망할(?) centos mariadb가 latin1_swedish_ci 이 기본인지라

생성했던 모든 데이터베이스와 테이블과 필드가 모두 이걸로 설정.. -_-


아무튼 가장 좋은건 DB 서버 설정시 캐릭터 셋과 콜레이션을 정해주고 시작하는건데

[링크 : http://nicesea.tistory.com/6]


그게 아니라면 일일이 하나씩 변경해 주는 수밖에.. ㅠㅠ


ALTER TABLE mytable CONVERT TO CHARACTER SET utf8  

[링크 : https://stackoverflow.com/questions/1294117/how-to-change-collation-of-database-table-column]

[링크 : https://zetawiki.com/wiki/MySQL_테이블_collation_변경]


'프로그램 사용 > mysql & mariaDB' 카테고리의 다른 글

mysql client 다른 호스트 접속하기  (0) 2018.12.20
ubuntu 18.04 apparmor와 mysql 충돌  (0) 2018.11.19
mariadb 캐릭터 셋  (0) 2018.09.13
Mariadb root access denied  (0) 2018.04.19
mysql sql문 변수 사용  (0) 2017.05.20
Posted by 구차니

centos 7에 mariadb 깔았는데

심하게 뜬금없에 latin1_swedish_ci로 설정이 되어있다.

아무튼 일일이 하나씩 변경을 해야하나..?


In MariaDB, the default character set is latin1, and the default collation is latin1_swedish_ci (however this may differ in some distros, see for example Differences in MariaDB in Debian). 

[링크 : https://mariadb.com/kb/en/library/setting-character-sets-and-collations/]

[링크 : https://slobell.com/blogs/38]

Posted by 구차니

skip-grant어쩌구 우회해서 접속하고 변경해도 안되길래

마구마구 검색을 해봤는데


mysql과 mariadb의 보안정책상 db에 root 계정 접속시에는

계정도 root로(그러니까 sudo 쓰던가) 접근해야 한다.

라는 결론


$ sudo mysql -uroot -p

[sudo] password for odroid:

Enter password:

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 34

Server version: 10.0.34-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04


Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


MariaDB [(none)]> 


[링크 : https://stackoverflow.com/.../access-denied-for-user-rootlocalhost-using-password-yes-after-new-instal]



+

라즈베리 파이는 5.5.59 버전으로 root에 로그인시 root 권한이 필요없다.

5.5~8.0 사이에 변화가 있었던거 같은데 changelog에서 뒤지다가 포기..

$ mysql --version

mysql  Ver 14.14 Distrib 5.5.59, for debian-linux-gnu (armv7l) using readline 6.3 


$ mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 367

Server version: 5.5.59-0+deb8u1 (Raspbian)


Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql>


mysql은

5.5/5.6/5.7->8.0 으로 점프했고


mariadb는 

5.5->10.0 으로 점프했다.

Posted by 구차니

mysql이 sql 표준과 다른건가

sql 문 자에로는 set 명령에서 변수 타입을 정해주어야 하나

mysql에서는 변수형 없이 바로 쓸 수 있는 듯


SET @V = 10;

SELECT @V + 1; 

[링크 : http://junny1909.tistory.com/259]

'프로그램 사용 > mysql & mariaDB' 카테고리의 다른 글

mariadb 캐릭터 셋  (0) 2018.09.13
Mariadb root access denied  (0) 2018.04.19
mysql view 출력 그리고 내용확인  (0) 2017.05.09
db varchar 와 char  (0) 2017.05.09
db에 mac / ip 저장하기(자료형)  (0) 2017.05.09
Posted by 구차니

mysql client로 콘솔에서 접속해서 보니..

걍.. table로 나온다.


mysql> show tables;

+-------------------+

| Tables_in_archlog |

+-------------------+

| account_bank      |

| account_periodic  |

| account_withdraw  |

| arch_article      |

| arch_blobs        |

| arch_refer        |

| arch_rel          |

| arch_reply        |

| arch_user         |

| org_detail        |

| org_rel           |

| organization      |

| people_detail     |

| people_rel        |

+-------------------+

14 rows in set (0.00 sec) 


mysql> desc organization;

+---------------+-----------+------+-----+---------+-------+

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

+---------------+-----------+------+-----+---------+-------+

| idx           | int(11)   | NO   |     | 0       |       |

| name_kr       | char(50)  | YES  |     | NULL    |       |

| name_en       | char(30)  | YES  |     | NULL    |       |

| address       | char(200) | YES  |     | NULL    |       |

| call_1        | char(30)  | YES  |     | NULL    |       |

| fax           | char(30)  | YES  |     | NULL    |       |

| web           | char(50)  | YES  |     | NULL    |       |

| certification | char(20)  | YES  |     | NULL    |       |

| time_create   | datetime  | YES  |     | NULL    |       |

+---------------+-----------+------+-----+---------+-------+

9 rows in set (0.01 sec)


그나저나 저 \G의 차이가 크게 나오네..

mysql> show create view organization\G

얘는 걍.. +--- 이런거 도배 됨

mysql> show create view organization; 

[링크 : https://dev.mysql.com/doc/refman/5.7/en/show-create-view.html]


\g는 vertical output 인가?

--auto-vertical-output

Cause result sets to be displayed vertically if they are too wide for the current window, and using normal tabular format otherwise. (This applies to statements terminated by ; or \G.) 

[링크 : https://dev.mysql.com/doc/refman/5.7/en/mysql-command-options.html]



+

full 하나 넣어주니 깔끔하게 구분이 되는군!

mysql> show full tables;

+-------------------+------------+

| Tables_in_archlog | Table_type |

+-------------------+------------+

| account_bank      | BASE TABLE |

| account_periodic  | BASE TABLE |

| account_withdraw  | BASE TABLE |

| arch_article      | BASE TABLE |

| arch_blobs        | BASE TABLE |

| arch_refer        | BASE TABLE |

| arch_rel          | BASE TABLE |

| arch_reply        | BASE TABLE |

| arch_user         | BASE TABLE |

| org_detail        | BASE TABLE |

| org_rel           | BASE TABLE |

| organization      | VIEW       |

| people_detail     | BASE TABLE |

| people_rel        | BASE TABLE |

+-------------------+------------+

14 rows in set (0.01 sec) 

[링크 : https://dev.mysql.com/doc/refman/5.7/en/show-tables.html]

'프로그램 사용 > mysql & mariaDB' 카테고리의 다른 글

Mariadb root access denied  (0) 2018.04.19
mysql sql문 변수 사용  (0) 2017.05.20
db varchar 와 char  (0) 2017.05.09
db에 mac / ip 저장하기(자료형)  (0) 2017.05.09
mysql innodb compress  (0) 2017.04.12
Posted by 구차니

char은 고정

varchar는 가변


다만, char의 경우 길이보다 짧게 입력시 공백으로 처리되어

equals로 비교시 같지 않다고 나오기에 trim()을 해주어야 한다는데 어쩌구 저쩌구


결론은.. 걍 유지보수 편하게 varchar로 대동단결? 이라는 건데

음.. varchar로 구성된 테이블 하나 두고 하나만 파편화 시키는 것도 방법이 되려나?


[링크 : https://okky.kr/article/217655]

[링크 : https://okky.kr/article/256528]

[링크 : http://database.sarang.net/?inc=read&aid=16220&criteria=mysql...page=16]

[링크 : http://dreamchallenger.blogspot.com/2011/07/char-varchar.html]

'프로그램 사용 > mysql & mariaDB' 카테고리의 다른 글

mysql sql문 변수 사용  (0) 2017.05.20
mysql view 출력 그리고 내용확인  (0) 2017.05.09
db에 mac / ip 저장하기(자료형)  (0) 2017.05.09
mysql innodb compress  (0) 2017.04.12
mysql view  (0) 2017.03.14
Posted by 구차니

MAC은 대개 48bit(8x6) 인데 일부에서는(인피니밴드) 8byte까지 늘어나는 듯

그리고 ip는 IPv4 기준 32bit 니까 int로도 충분은 한데...


쿼리 문에서는 HEX로 변환해주고

[링크 : https://dev.mysql.com/doc/refman/5.7/en/hexadecimal-literals.html]


php에서는 base_convert()를 이용해서 값을 변환해서 비교하는 듯?

[링크 : http://php.net/manual/en/function.base-convert.php]



[링크 : http://stackoverflow.com/questions/4514547/mysql-best-way-to-store-mac-addresses]

[링크 : http://www.onurguzel.com/storing-mac-address-in-a-mysql-database/]

[링크 : http://bryan.wiki/34]

'프로그램 사용 > mysql & mariaDB' 카테고리의 다른 글

mysql view 출력 그리고 내용확인  (0) 2017.05.09
db varchar 와 char  (0) 2017.05.09
mysql innodb compress  (0) 2017.04.12
mysql view  (0) 2017.03.14
db designer  (0) 2017.03.14
Posted by 구차니