データベース・テーブルの作成、クエリーおよび削除(ワークベンチ)


このクリップにフォルダを作成し、worknechによって作成されたSQLクエリー文を保存します.
1.このクリップに保存するフォルダを作成する
新-project-maven project-create a simple project(プロトタイプ選択をスキップ)チェック
group id : com.douzone
artifact id : mariadb-practices
packaging : pom
finish
mariadb-practicesプロジェクトsrcを削除しない(不要)
保存するフォルダを2つ作成
mariadb-practices右クリック-new-フォルダ
フォルダ名:
1.sql練習
2.練習問題(次の課題を保存する場所)
gitignoreを生成する(羽毛を接続するために)
mariadb-practices右クリック-new-file-ファイル名:.gitignore
.gitignoreコンテンツ
**/.classpath
**/.project
**/.settings
**/.target
**/.build
README.md作成
mariadb-practices右クリック-new-file-ファイル名:README.md
うちわ
1.襟元にレジストリを作成する
名前:mariadb-practices
リンクのコピー
2.バインド
mariadb-実践右クリック-チーム共有プロジェクト-プロジェクト親フォルダのリポジトリ(ワークベンチsqlドキュメントの格納場所)を使用または作成-下部のCreate Repository Finishをクリック
羽Perspectiveでtest 01のRemotesを右クリック-Remotes-構成取得の作成-作成-(羽リンククリップボードに保存)変更をクリック-完了-保存とFetch
ドキュメントの襟のダンプとプッシュ後、襟に
ワークベンチの使用方法
必要な動作を指定する行でCtrl+Enterキー
ex)
create table pet(//テープ作成)の作成
select name, owner, species, gender, birth, death from pet;//朝礼
ワークベンチクエリー文の作成
接続されたwebdbアカウントを開く-次のクエリー文を作成します.
先事
1.エラー)*sql文実行中のキーエラー
Edit-preferences-Sql Editor-下部でのSafe Updatesの実行をキャンセルします(UPDATEおよびDELETEは制限なく拒否されます).
2.エラー)接続権限の設定
ワークベンチメイン画面—MySQL ConnectionsのWebdb右クリック-エディットConnection-InFILE=1に追加された上部OPT LOCAL INTERS:
パーミッションが許可されると、OPT LOCAL INFILE=1はクリアして再起動できる
Webdbアカウントを切断および再接続するには、権限を再設定する必要があります.
3.クエリー文からインポートするデータをダウンロードする
より高度なGoogleドライブ-リソース-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;
ちょぞう
ファイル保存スクリプトas-フォルダパスの検索
フォルダパス:eclips workspace-mariadb-practice-sql練習に保存
読み込み
接続されたwebdbアカウントを開く
File-open sql script-保存した場所のsqlドキュメントを開く
バックアップされたdbデータ(従業員)ワークベンチにインポート
1.練習用のバックアップデータファイルのダウンロード
より高度なGoogleドライブ-リソース-MySQL-従業員db.zipのダウンロード-Cドライブに移動
2.sftpを使用してzipファイルをサーバに移動
環境かんきょう:xshell xshell
[c:~]$ cd c:\
[C:]$ sftp [email protected]
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
3.xshellに解凍機能をインストールする
環境かんきょう:xshell xshell
[root@lx ~]# yum -y install unzip
[root@lx ~]# unzip employees_db.zip
4.dbデータワークベンチへのインポート
環境かんきょう:xshell 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パスワード
4.作成したhrアカウントワークベンチへの接続
ワークベンチのホームページでMySQL Connections+をクリック
  • 接続名(メイン画面表示):hr
  • Hostname : 127.0.0.1 - Port : 3306
  • Username : hr
  • Default Schema : hr
    Test Connection-xshell指定パスワードhr入力後確認
    ワークベンチからhrアカウントを接続する
    空のドキュメント
    desc employees;//データベースパターンの検証
    select count(*) from employees;//チェックカウント
    CTRL Enterキーを押すと
  • が表示されます.