Ubuntu 에 MariaDB를 설치했고 JDBC , J Connector 도 설치했다 

이제 Java 코드를 작성하여 DB에 데이터를 삽입 해 보자.

1. sample DB 만들기

2. 사용자 만들고 권한 주기

3. Java 코드 만들어 실행하기


1. mysql root로 진입하여 한번 둘러본다.

root@ncpmicro:/home# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 31
Server version: 10.1.48-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.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.

2. Sample DB 생성

MariaDB [(none)]> create database test_db;

3. Table 생성

CREATE TABLE `song_table` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(15) NOT NULL,
  `videoId` varchar(15) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4

팁) SQL 구문 추출

MariaDB [test_db]> show create table song_table;

4. 데이터 삽입

INSERT INTO song_table (title, videoId) VALUE('제복1', '1234567');

5. 사용자를 생성한다.

MariaDB [(none)]> create user 'cd'@'%' identified by '1234';
Query OK, 0 rows affected (0.00 sec)

6. 권한설정

MariaDB [(none)]> grant all privileges on test_db.* to 'cd'@'%';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;

 

7. 새로 생성된 user로 test_db로 접근한다.

root@ncpmicro:/home# mysql -u cd -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 33
Server version: 10.1.48-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.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.

8. DB 선택

MariaDB [(none)]> use test_db
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

9. 데이터 조회

MariaDB [test_db]> select * from song_table;
+----+---------+----------+
| id | title   | videoId  |
+----+---------+----------+
|  1 | 제복1   | 1234567  |
|  2 | title2  | videoid2 |
|  3 | title2  | videoid2 |
|  4 | title2  | videoid2 |
+----+---------+----------+
4 rows in set (0.00 sec)

10. 

vi file_name - 파일편집

 

Esc - 명령모드

:q! - 나가기

:wq! - 저장하고 나가기

 

i - 인서트 모드

gg - 처음으로 가기

shift - v 한줄 선택

/문자열 - 문자열 찾기

 

마우스 드래그 - 드래그 부분이 복사됨

마우스 오른쪽 클릭 - 붙여넣기

 

MariaDB

1. 아래 MariaDB 홈페이지 방문

 

Download MariaDB Connectors for data access & analysis | MariaDB

Download MariaDB Connector/Python, MariaDB Connector/C, MariaDB Connector/J, MariaDB Connector/Node.js, MariaDB Connector/R2DBC, MariaDB Connector/ODBC and more

mariadb.com

 

2. Connectors 탭에서 Java8 옵션을 선택했고 아래에 파일 url 이 표시된다

3. Java8 Connector 파일을 wget 으로 다운 받아본다.

root@ncpmicro:/home# wget https://dlm.mariadb.com/1611425/Connectors/java/connector-java-3.0.0-alpha/mariadb-java-client-3.0.0-alpha.jar

 

4. 다운로드한 jar 파일을 java 설치디렉토리의 /lib/ext 디레토리에 복사한다.

root@ncpmicro:/home# cp mariadb-java-client-3.0.0-alpha.jar /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext

5. CLASSPATH 를 정의하기 위해 ~/.bashrc 수정

root@ncpmicro:/home# vi ~/.bashrc

6. 추가후 저장 - 각자 사정에 따라 다를 수 있음.

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export PATH="$PATH:$JAVA_HOME/bin"
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib/tools.jar:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/ext:.

7. 실행시킨다.

root@ncpmicro:/home# source ~/.bashrc

8. 이제 Java 소스를 컴파일 하여 MariaDB 를 테스트 할 수 있다.

그전에 테스트할 DB를 준비해야 하니 다음 편에 

요약
mysql
SHOW DATABASES;
USE database_name;
SHOW TABLES;
DESC table_name;

SHOW TABLE STATUS;
SELECT * FROM table_name;
exit

마리아DB 설치 명령 

apt install mariadb-server 입력해주면 아래와 같이 실행된다.

root@ncpmicro:~# apt install mariadb-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
...
...
...
0 upgraded, 29 newly installed, 0 to remove and 19 not upgraded.
Need to get 24.0 MB of archives.
After this operation, 184 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Y를 입력하면 한동안 설치 작업을 한다.

Get:1 http://kr.archive.ubuntu.com/ubuntu bionic/main amd64 mysql-common all 5.8+1.0.4 [7,308 B]
...
(중략)
...
Get:29 http://kr.archive.ubuntu.com/ubuntu bionic-updates/universe amd64 mariadb-server all 1:10.1.48-0ubuntu0.18.04.1 [12.9 kB]
Fetched 24.0 MB in 7s (3,242 kB/s)
Preconfiguring packages ...
Selecting previously unselected package mysql-common.
(Reading database ... 126286 files and directories currently installed.)
...
...
Unpacking mariadb-server (1:10.1.48-0ubuntu0.18.04.1) ...
Setting up libhtml-tagset-perl (3.20-3) ...
...
...
Setting up mariadb-server-10.1 (1:10.1.48-0ubuntu0.18.04.1) ...
Setting up mariadb-server (1:10.1.48-0ubuntu0.18.04.1) ...
Processing triggers for libc-bin (2.27-3ubuntu1.4) ...
...
root@ncpmicro:~#

몇분 걸린듯 설치 끝 !!

 

시작하고 종료해 보기

mysql

exit

root@ncpmicro:~# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 41
Server version: 10.1.48-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.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)]>
MariaDB [(none)]> exit
Bye
root@ncpmicro:~#

 

데이터베이스 명령어는 대문자 소문자를 가리지 않지만

가독성을 위해 대문자를 사용한다고 합니다.

 

데이터베이스 목록 보고 사용하기

SHOW DATABASES;

USE database;

root@ncpmicro:~# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 43
Server version: 10.1.48-MariaDB-0ubuntu0.18.04.1 Ubuntu 18.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)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]>

사용할 데이터베이스 테이블 조회 

SHOW TABLES;

MariaDB [mysql]> SHOW TABLES;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| column_stats              |
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| gtid_slave_pos            |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| index_stats               |
| innodb_index_stats        |
| innodb_table_stats        |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| roles_mapping             |
| servers                   |
| slow_log                  |
| table_stats               |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
30 rows in set (0.00 sec)

MariaDB [mysql]>

테이블 속성 보기

DESC table_name;

MariaDB [mysql]> desc user;
+------------------------+-----------------------------------+------+-----+----------+-------+
| Field                  | Type                              | Null | Key | Default  | Extra |
+------------------------+-----------------------------------+------+-----+----------+-------+
| Host                   | char(60)                          | NO   | PRI |          |       |
| User                   | char(80)                          | NO   | PRI |          |       |
| Password               | char(41)                          | NO   |     |          |       |
| Select_priv            | enum('N','Y')                     | NO   |     | N        |       |
| Insert_priv            | enum('N','Y')                     | NO   |     | N        |       |
| Update_priv            | enum('N','Y')                     | NO   |     | N        |       |
| Delete_priv            | enum('N','Y')                     | NO   |     | N        |       |
| Create_priv            | enum('N','Y')                     | NO   |     | N        |       |
| Drop_priv              | enum('N','Y')                     | NO   |     | N        |       |
| Reload_priv            | enum('N','Y')                     | NO   |     | N        |       |
| Shutdown_priv          | enum('N','Y')                     | NO   |     | N        |       |
| Process_priv           | enum('N','Y')                     | NO   |     | N        |       |
| File_priv              | enum('N','Y')                     | NO   |     | N        |       |
| Grant_priv             | enum('N','Y')                     | NO   |     | N        |       |
| References_priv        | enum('N','Y')                     | NO   |     | N        |       |
| Index_priv             | enum('N','Y')                     | NO   |     | N        |       |
| Alter_priv             | enum('N','Y')                     | NO   |     | N        |       |
| Show_db_priv           | enum('N','Y')                     | NO   |     | N        |       |
| Super_priv             | enum('N','Y')                     | NO   |     | N        |       |
| Create_tmp_table_priv  | enum('N','Y')                     | NO   |     | N        |       |
| Lock_tables_priv       | enum('N','Y')                     | NO   |     | N        |       |
| Execute_priv           | enum('N','Y')                     | NO   |     | N        |       |
| Repl_slave_priv        | enum('N','Y')                     | NO   |     | N        |       |
| Repl_client_priv       | enum('N','Y')                     | NO   |     | N        |       |
| Create_view_priv       | enum('N','Y')                     | NO   |     | N        |       |
| Show_view_priv         | enum('N','Y')                     | NO   |     | N        |       |
| Create_routine_priv    | enum('N','Y')                     | NO   |     | N        |       |
| Alter_routine_priv     | enum('N','Y')                     | NO   |     | N        |       |
| Create_user_priv       | enum('N','Y')                     | NO   |     | N        |       |
| Event_priv             | enum('N','Y')                     | NO   |     | N        |       |
| Trigger_priv           | enum('N','Y')                     | NO   |     | N        |       |
| Create_tablespace_priv | enum('N','Y')                     | NO   |     | N        |       |
| ssl_type               | enum('','ANY','X509','SPECIFIED') | NO   |     |          |       |
| ssl_cipher             | blob                              | NO   |     | NULL     |       |
| x509_issuer            | blob                              | NO   |     | NULL     |       |
| x509_subject           | blob                              | NO   |     | NULL     |       |
| max_questions          | int(11) unsigned                  | NO   |     | 0        |       |
| max_updates            | int(11) unsigned                  | NO   |     | 0        |       |
| max_connections        | int(11) unsigned                  | NO   |     | 0        |       |
| max_user_connections   | int(11)                           | NO   |     | 0        |       |
| plugin                 | char(64)                          | NO   |     |          |       |
| authentication_string  | text                              | NO   |     | NULL     |       |
| password_expired       | enum('N','Y')                     | NO   |     | N        |       |
| is_role                | enum('N','Y')                     | NO   |     | N        |       |
| default_role           | char(80)                          | NO   |     |          |       |
| max_statement_time     | decimal(12,6)                     | NO   |     | 0.000000 |       |
+------------------------+-----------------------------------+------+-----+----------+-------+
46 rows in set (0.00 sec)

MariaDB [mysql]>

테이블 상태 조회

SHOW TABLE STATUS;

MariaDB [mysql]> show table status;
+---------------------------+--------+---------+------------+------+----------------+-------------+--------------------+--------------+-----------+----------------+---------------------+---------------------+---------------------+-------------------+----------+--------------------+---------------------------------------------------+
| Name                      | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length    | Index_length | Data_free | Auto_increment | Create_time         | Update_time         | Check_time          | Collation         | Checksum | Create_options     | Comment                                           |
+---------------------------+--------+---------+------------+------+----------------+-------------+--------------------+--------------+-----------+----------------+---------------------+---------------------+---------------------+-------------------+----------+--------------------+---------------------------------------------------+
| column_stats              | MyISAM |      10 | Dynamic    |    0 |              0 |           0 |    281474976710655 |         4096 |         0 |           NULL | 2021-08-26 15:26:50 | 2021-08-26 15:26:50 | NULL                | utf8_bin          |     NULL |                    | Statistics on Columns                             |
| columns_priv              | MyISAM |      10 | Fixed      |    0 |              0 |           0 | 282037926664077311 |         4096 |         0 |           NULL | 2021-08-26 15:27:19 | 2021-08-26 15:27:19 | 2021-08-26 15:27:19 | utf8_bin          |     NULL |                    | Column privileges                                 |
...
...
| user                      | MyISAM |      10 | Dynamic    |    1 |             72 |          72 |    281474976710655 |         4096 |         0 |           NULL | 2021-08-26 15:27:31 | 2021-08-26 15:27:31 | NULL                | utf8_bin          |     NULL |                    | Users and global privileges                       |
+---------------------------+--------+---------+------------+------+----------------+-------------+--------------------+--------------+-----------+----------------+---------------------+---------------------+---------------------+-------------------+----------+--------------------+---------------------------------------------------+

 

테이블 데이터 조회하기

SELECT * FROM table;

MariaDB [mysql]> select * from help_category;
+------------------+-----------------------------------------------+--------------------+-----+
| help_category_id | name                                          | parent_category_id | url |
+------------------+-----------------------------------------------+--------------------+-----+
|                1 | Geographic                                    |                  0 |     |
|                2 | Polygon properties                            |                 34 |     |
|                3 | WKT                                           |                 34 |     |
|                4 | Numeric Functions                             |                 38 |     |
|                5 | Plugins                                       |                 35 |     |
|                6 | MBR                                           |                 34 |     |
|                7 | Control flow functions                        |                 38 |     |
|                8 | Transactions                                  |                 35 |     |
|                9 | Help Metadata                                 |                 35 |     |
|               10 | Account Management                            |                 35 |     |
|               11 | Point properties                              |                 34 |     |
|               12 | Encryption Functions                          |                 38 |     |
|               13 | LineString properties                         |                 34 |     |
|               14 | Miscellaneous Functions                       |                 38 |     |
|               15 | Logical operators                             |                 38 |     |
|               16 | Functions and Modifiers for Use with GROUP BY |                 35 |     |
|               17 | Information Functions                         |                 38 |     |
|               18 | Comparison operators                          |                 38 |     |
|               19 | Bit Functions                                 |                 38 |     |
|               20 | Table Maintenance                             |                 35 |     |
|               21 | User-Defined Functions                        |                 35 |     |
|               22 | Data Types                                    |                 35 |     |
|               23 | Compound Statements                           |                 35 |     |
|               24 | Geometry constructors                         |                 34 |     |
|               25 | GeometryCollection properties                 |                  1 |     |
|               26 | Administration                                |                 35 |     |
|               27 | Data Manipulation                             |                 35 |     |
|               28 | Utility                                       |                 35 |     |
|               29 | Language Structure                            |                 35 |     |
|               30 | Geometry relations                            |                 34 |     |
|               31 | Date and Time Functions                       |                 38 |     |
|               32 | WKB                                           |                 34 |     |
|               33 | Procedures                                    |                 35 |     |
|               34 | Geographic Features                           |                 35 |     |
|               35 | Contents                                      |                  0 |     |
|               36 | Geometry properties                           |                 34 |     |
|               37 | String Functions                              |                 38 |     |
|               38 | Functions                                     |                 35 |     |
|               39 | Data Definition                               |                 35 |     |
+------------------+-----------------------------------------------+--------------------+-----+
39 rows in set (0.00 sec)

MariaDB [mysql]>
요약
mysql
SHOW DATABASES;
USE database_name;
SHOW TABLES;
SHOW TABLE STATUS;
SELECT * FROM table_name;
exit

Ubuntu 우분투 명령어 노트

uname

root@ncpmicro:~# uname -a
Linux ncpmicro 4.15.0-118-generic #119-Ubuntu SMP Tue Sep 8 12:30:01 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
root@ncpmicro:~#

 

cat /etc/os-release 

"Ubuntu 18.04" 를 얻기위해

root@ncpmicro:~# cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.5 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.5 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic
root@ncpmicro:~#

cp 파일 복사

mv 이동

rm 파일삭제

date 현재시간

mkdir 디렉토리 만들기

rmdir 디렉토리 삭제

cat 파일내용출력

ls -al 디렉토리 및 파일 리스트 보기

ls -t 파일 시간 소팅

ls -r 파일 리버스 소팅

ls -S 파일 사이즈 소팅

 

(응용) ls -al > filelist.txt

root@ncpmicro:~# ls -al > filelist.txt
root@ncpmicro:~# ls
filelist.txt
root@ncpmicro:~# cat filelist.txt
total 64
drwx------  8 root root  4096 Aug 26 15:07 .
drwxr-xr-x 26 root root  4096 Aug 12 18:26 ..
-rw-------  1 root root     0 Aug 26 14:47 .bash_history
-rw-r--r--  1 root root  3192 Aug 13 13:56 .bashrc
drwx------  2 root root  4096 Aug 10 23:49 .cache
-rw-r--r--  1 root root     0 Aug 26 15:07 filelist.txt
drwx------  3 root root  4096 Oct  6  2020 .gnupg
drwxr-xr-x  3 root root  4096 Oct  6  2020 .local
drwxr-xr-x  2 root root  4096 Aug 26 06:53 .nsight
-rw-r--r--  1 root root   148 Aug 18  2015 .profile
-rw-r--r--  1 root root    75 Oct  6  2020 .selected_editor
drwx------  2 root root  4096 Oct  6  2020 .ssh
drwxr-xr-x  2 root root  4096 Aug 23 17:50 .vim
-rw-------  1 root root 14969 Aug 26 15:03 .viminfo
-rw-r--r--  1 root root   176 Aug 13 17:49 .wget-hsts
root@ncpmicro:~#

grep '찾을문자열' *

파일안에서 문자열 찾기

2021년 8월 기준

주거용 오피스텔도 노령주택연금을 받을 수 있는지 문의해 보았는데요

가능하다고 합니다.

 

요건 및 특징

1. 몇가지 요건을 충족해야 합니다.

2. 주택에 비해 70~ 80% 수령금액이 작습니다. 

Peggy und Marco Lachmann-Anke by Pixabay.com

오피스텔 요건을 살펴보면

주거목적 오피스텔은 등기사항증명서상 건물내역에 오피스텔 이어야 하며

실사를 통해 주택연금 가입자가 해당 오피스텔에 주민등록을 전입하여

실제 거주하고 입식부엌 등 주거시설을 갖추고

'지방세 세목별 과세증명서' 상 주택으로 기재되어 주택분 재산세가 과세되고 있어야 합니다.

 

공시가격 9억원 까지는 주택연금 가입이 가능하다고 합니다.

 

 

 

한국주택금융공사

특례보금자리론, 유동화증권, 전세자금보증, 건설자금보증, 주택연금 업무.

www.hf.go.kr

 

 

문의해 보세요~

남성 반지갑 

 

대충 사면 되는데 하지만 막상 고민하게 된다. 

 

남성 반지갑 가성비 좋은 놈으로 결정.

 

루이까또즈 남성 반지갑 

 

루이까또즈 공식 몰에 가서 이런 저런 할인 받고 저렴하게 하지만 예쁘게 샀다. 

 

마크가 너무 큰 듯 한데 깜장색이라 잘 안보이니 괜찮다.

이제 바지 뒷 주머니 안꼽을라고 가방도 하나 사야겠는데 

완전 자세 안나온다 

이정도면 가성비 정말 좋은듯하다.

예방접종 후 이상반응

 

예방접종 후 흔하게 발생하는 증상

예방접종 후에 아래와 같은 증상이 흔하게 발생할 수 있으며, 이는 면역이 형성되는 과정에서 나타날 수 있는 반응으로 대부분 2-3일 이내에 사라집니다.

접종부위 통증, 부기, 발적 발열, 메스꺼움, 근육통 피로감 두통

 

예방접종 후, 이런 증상이 생기면

접종부위 부기 통증이 있는 경우 깨끗한 수건으로 냉찜질을 해주세요.

미열이 있는 경우 수분을 충분히 섭취하고 쉬세요.

전신통증이나 발열등으로 불편함이 있는 경우에는, 해열진통제가 도움이 될 수 있습니다.

접종 전 미리 해열 진통제를 준비하시고, 증상이 나타나면 바로 복용하세요

매일 진통제 복용에 제한은 없으나, 가급적 염증제거 효과가 없는 아세트아미노펜 성분의 의약품을 복용 바랍니다.

코로나 19 예방접종 후 이상반응 발생이 의심되는 경우

|대부분 해열·진통제 복용으로 증상이 호전되나 12일 이상 접종부위부가 통증 발전 등이 지속된다면 의사의 진료를 받으세요

만일 호흡곤란, 의식소실, 안면부종 등을 동반한 심각한 알레르기반응(아나필락시스 등)이 나타난 경우에는 즉시 119로 연락하거나 가까운 응급실로 내원하시기 바랍니다.


이럴 땐, 의사진료를 받으세요.

* 접종 후 접종부위 부기, 통증, 발적이 48시간이 지나도 호전되지 않는 경우 •접종 후 심한 또한 2일 이상의 지속적인 두통이 발생하며, 진통제에 반응하지 않거나 조절되지 않는 경우 또는 시야가 흐려지는 경우 접종 후 갑자기 기운이 떨어지거나 평소와 다른 이상증상이 나타난 경우 •접종 후 접종부위가 아닌 곳에서 멍이나 출혈이 생긴 경우

• 접종 후 4주 내 호흡곤란, 흉통, 지속적인 복부통증, 다리 부기와 같은 증상이 나타난 경우




+ Recent posts