new - project - maven project - create a simple project (skip archetype selection) 체크
group id : com.douzone
artifact id : mariadb-practices
packaging : pom
finish
mariadb-practices 프로젝트 안 src삭제 (필요없음)
mariadb-practices 우클릭 - new - 폴더
폴더 이름 :
1. sql연습
2. 연습문제 (앞으로 과제 저장할 위치)
mariadb-practices 우클릭 - new - 파일 - 파일이름 : .gitignore
.gitignore 내용
**/.classpath
**/.project
**/.settings
**/.target
**/.build
mariadb-practices 우클릭 - new - 파일 - 파일이름 : README.md
이름 : mariadb-practices
깃 링크 복사하기
mariadb-practices 우클릭 - Team - Share project - Use or create repository in parent folder of project(워크벤치 sql문서 저장할 위치) - 밑에 create Repository 클릭 - Finish
깃 Perspective에서 test01의 Remotes 우클릭 - Create Remotes - Configure fetch - Create - (깃 링크 클립보드에 저장된상태에서)Change 클릭 - finish - save and Fetch
문서 깃 스테이징하고 푸쉬하면 깃에 올라가있음
원하는 행동을 명시하는 라인에서 Ctrl + Enter
ex)
create table pet( // 테이블생성
select name, owner, species, gender, birth, death from pet; // 조회
커넥션된 webdb 계정 열기 - 밑의 쿼리문 작성하기
Edit - Preferences - Sql Editor - 맨밑에 Safe Updates (rejects UPDATEs and DELETEs with no restrictions) 체크해제
워크벤치 메인화면 - MySQL Connections의 webdb 우클릭 - Edit Connection - Advanced - Others:의 맨위에 OPT_LOCAL_INFILE=1 추가
권한 허용 후에 OPT_LOCAL_INFILE=1 지우고 껐다 켜도 잘 실행됨
webdb 계정 연결을 해제하고 다시 연결하려면 권한 설정 다시해줘야함
더존 구글 드라이브 - 자료 - MySQL - pet.txt 다운받기 - C드라이브에 넣기
-- Basic Query // -- : 주석
drop table pet;
create table pet( //테이블 생성하고싶을때 커서올리고 Ctrl Enter
name varchar(20), //컬럼지정
owner varchar(20),
species varchar(20), //varchar은 가변적 (네임같은것에 쓰임)
gender char(1), //char 고정적 (주민번호같은것에 쓰임)
birth DATE,
death DATE
);
-- 조회
select name, owner, species, gender, birth, death from pet;
-- 데이터 넣기(생성, create)
insert
into pet
value ('성탄이', '안대혁', 'dog', 'm', '2018-12-25', null);
-- 데이터 삭제(delete)
delete
from pet
where name = '성탄이';
-- load data local infile
load data local infile 'C:\\pet.txt' into table pet;
--- update death
update pet
set death = null
where name != 'Bowser';
-- 조회연습1: where
-- 1990년 이후에 태어난 아이들은?
select name, species, birth
from pet
where birth > '1990-12-31';
--- Gwen과 함께 사는 아이들은 ?
select name, species, owner
from pet
where owner = 'Gwen';
--- null 다루기 1 : 살아있는 애들은?
select name, birth, death
from pet
where death is null;
--- null 다루기 2 : 죽은 애들은?
select name, birth, death
from pet
where death is not null;
-- like 검색(패턴 매칭) : 이름이 b로 시작하는 아이들은?
select name from pet where name like 'b%';
-- like 검색(패턴 매칭) : 이름이 b로 시작하는 아이들중에 이름이 6자인 아이는?
select name from pet where name like 'b_____';
-- 집계(통계) 함수
select count(*) from pet;
select count(death) from pet;
select count(*) from pet where death is not null;
File - Save script as - 폴더 경로 찾기
폴더경로 : eclips workspace - mariadb-practices- sql 연습에저장
커넥션된 webdb 계정 열기
File - open sql script - 저장햇던위치의 sql 문서 열기
더존 구글 드라이브 - 자료 - MySQL - employees_db.zip 다운로드받기 - C드라이브에 옮김
환경 : xshell
[c:~]$ cd c:\
[C:]$ sftp webmaster@127.0.0.1
sftp : put employees_db.zip
[C:]$ open
[webmaster@lx ~]$ ls -l
[webmaster@lx ~]$ su -
[root@lx ~]# mv /home/webmaster/employees_db.zip .
[root@lx ~]# ls -l
환경 : xshell
[root@lx ~]# yum -y install unzip
[root@lx ~]# unzip employees_db.zip
환경 : xshell
새 세션
[c:~]$ open
[webmaster@lx ~]$ su -
[root@lx ~]# mysql -p
create user 'hr'@'10.0.2.2' identified by 'hr';
MariaDB [(none)]> create database employees;
MariaDB [(none)]> create user 'hr'@'10.0.2.2' identified by 'hr';
MariaDB [(none)]> grant all privileges on employees.* to 'hr'@'10.0.2.2';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> exit
[root@lx ~]# cd employees_db
[root@lx employees_db]# mysql -p < employees.sql
Enter password: root 비밀번호
워크벤치 메인화면에 MySQL Connections + 클릭