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.
'start linux' 카테고리의 다른 글
Ubuntu MariaDB + JSP RESTAPI request 받아 XML response 해보기 (0) | 2021.09.04 |
---|---|
[ Linux ] Ubuntu MariaDB 대량 데이터 밀어 넣기 (0) | 2021.09.01 |
[ Linux ] vi 에디터 명령어 노트 (0) | 2021.08.30 |
[ Linux ] Ubuntu MariaDB Java Connectors 설치 (0) | 2021.08.29 |
[ Linux ] Ubuntu MariaDB 설치 (0) | 2021.08.26 |