MySQLコアテクノロジ
8876 ワード
1.データベースとは
既存のデータストレージ方式はどれらがありますか?
JAvaプログラムはデータ(変数、オブジェクト、配列、集合)を格納し、データはメモリに保存され、瞬間状態記憶に属する
ファイルはデータを保存し、ハードディスクに保存し、永続的な状態の記憶に属する
以上のストレージ方式の欠点
データ型の区分がない
ストレージ・データ・レベルが小さい
アクセス制限なし
バックアップなし、リカバリメカニズム
二、データベース
データベースは、データ構造に基づいてデータを整理、格納、管理する倉庫です.長期にわたって計算に格納され、組織化され、共有され、統一的に管理されるデータの集合です.
データベースの分類:網状構造データベース、米ゼネラル・エレクトロニクス、ノード形式で格納およびアクセス.
階層データベース:IBM社のIMSは、ツリー構造の実装のためのストレージとアクセスを指向しています.
リレーショナル構造データベース:oracle,db 2,mysql,sql server,テーブルストレージ,マルチテーブル間関連関係を確立し,分類,連結,接続,選択などの演算によりアクセスを実現する.
非リレーショナル・データベース:elastecsearch,mongodb,redisの多くはハッシュ・テーブルを使用し、テーブル内でキー値(key-value)で特定のキーとポインタが特定のデータを指すことを実現します.
三、データベース管理システム
コンセプト
データベース管理システム:データベースのセキュリティと完全性を保証するために、データベースを構築、使用、維持するための大規模なソフトウェアを指し、データベースを統一的に管理し、制御し、ユーザーがデータベース管理システムを通じてデータベースのデータにアクセスする.
一般的なデータベース管理システム
oracle:業界で現在比較的成功しているリレーショナル・データベース・システムと考えられています.
db2
sqllite:携帯電話端末のデータベース
2、mysqlの紹介
Windowsはmysqlをインストールするのは比較的に簡単で、これはbaiduでいいです
アンインストールのプロセス:
コンソールのアンインストール
mysqlのインストールディレクトリを見つけて削除
programdata mysqlの削除
mysqlディレクトリ構造
bin-実行可能なコマンド
lib---ライブラリファイル
include--ヘッダファイル
Share--文字セット、言語などの情報
mysqlプロファイル
mysqlインストールディレクトリでmyを見つけます.iniファイルを開きmy.iniファイルいくつかの一般的な構成パラメータを表示
パラメータ---------------説明
default-character-setクライアントデフォルト文字セット
character-set-serverサービス側デフォルト文字セット
portクライアントとサービス側のポート番号
default-storage-engine mysqlデフォルトストレージエンジンinnodb
五、sql言語
コンセプト
sql構造化クエリー言語は、データを格納し、データベースシステムを更新し、クエリーし、管理するためのプログラム設計言語です.
経験:通常、データベースの削除変更を実行し、curdと略称します.
mysqlアプリケーション
データベースの操作にはmysql環境に入って命令の入力を行い、1つの命令の末尾で使用する必要があります.の最後の部分
基本コマンド
mysql内のすべてのデータベースを表示
show databases;
データベース名
説明
information_schema
データベース名やテーブル名、列のデータ型やアクセス権など、すべてのデータベースに関する情報(メタデータ)メタデータが保存されている情報データベース
mysql
コアデータベースは、主にデータベースのユーザー、権限の設定、キーワードなどを保存し、使用する制御と管理情報を削除することはできません.
performance_schema
パフォーマンス最適化データベース、mysql 5.5バージョンに追加されたパフォーマンスに優れたエンジン
sys
システムデータベース、mysql 5.7バージョンに追加されたメタデータ情報を迅速に理解できるシステムライブラリは、データベースの多様な情報を発見しやすく、パフォーマンスのボトルネックの問題を解決します.
データベース関連アクション
3、データ照会、DML操作
データベース・テーブルの基本構造
リレーショナル構造のデータベースはテーブル(table)でデータ格納され、テーブルは行と列グループによって格納されます.
経験:クエリー文を実行して返される結果セットは仮想テーブルです.
基本クエリー
構文selectカラム名fromテーブル名
キーワードの説明
selectクエリーするテーブルを指定
fromはクエリーするテーブルを指します
4、サブクエリ(条件判断として)
5、DML操作
新規作成
Insert intoテーブル名(カラム名)values(値1,値2)
6、SQL言語分類
既存のデータストレージ方式はどれらがありますか?
JAvaプログラムはデータ(変数、オブジェクト、配列、集合)を格納し、データはメモリに保存され、瞬間状態記憶に属する
ファイルはデータを保存し、ハードディスクに保存し、永続的な状態の記憶に属する
以上のストレージ方式の欠点
データ型の区分がない
ストレージ・データ・レベルが小さい
アクセス制限なし
バックアップなし、リカバリメカニズム
二、データベース
データベースは、データ構造に基づいてデータを整理、格納、管理する倉庫です.長期にわたって計算に格納され、組織化され、共有され、統一的に管理されるデータの集合です.
データベースの分類:網状構造データベース、米ゼネラル・エレクトロニクス、ノード形式で格納およびアクセス.
階層データベース:IBM社のIMSは、ツリー構造の実装のためのストレージとアクセスを指向しています.
リレーショナル構造データベース:oracle,db 2,mysql,sql server,テーブルストレージ,マルチテーブル間関連関係を確立し,分類,連結,接続,選択などの演算によりアクセスを実現する.
非リレーショナル・データベース:elastecsearch,mongodb,redisの多くはハッシュ・テーブルを使用し、テーブル内でキー値(key-value)で特定のキーとポインタが特定のデータを指すことを実現します.
三、データベース管理システム
コンセプト
データベース管理システム:データベースのセキュリティと完全性を保証するために、データベースを構築、使用、維持するための大規模なソフトウェアを指し、データベースを統一的に管理し、制御し、ユーザーがデータベース管理システムを通じてデータベースのデータにアクセスする.
一般的なデータベース管理システム
oracle:業界で現在比較的成功しているリレーショナル・データベース・システムと考えられています.
db2
sqllite:携帯電話端末のデータベース
2、mysqlの紹介
Windowsはmysqlをインストールするのは比較的に簡単で、これはbaiduでいいです
アンインストールのプロセス:
コンソールのアンインストール
mysqlのインストールディレクトリを見つけて削除
programdata mysqlの削除
mysqlディレクトリ構造
bin-実行可能なコマンド
lib---ライブラリファイル
include--ヘッダファイル
Share--文字セット、言語などの情報
mysqlプロファイル
mysqlインストールディレクトリでmyを見つけます.iniファイルを開きmy.iniファイルいくつかの一般的な構成パラメータを表示
パラメータ---------------説明
default-character-setクライアントデフォルト文字セット
character-set-serverサービス側デフォルト文字セット
portクライアントとサービス側のポート番号
default-storage-engine mysqlデフォルトストレージエンジンinnodb
五、sql言語
コンセプト
sql構造化クエリー言語は、データを格納し、データベースシステムを更新し、クエリーし、管理するためのプログラム設計言語です.
経験:通常、データベースの削除変更を実行し、curdと略称します.
mysqlアプリケーション
データベースの操作にはmysql環境に入って命令の入力を行い、1つの命令の末尾で使用する必要があります.の最後の部分
基本コマンド
mysql内のすべてのデータベースを表示
show databases;
データベース名
説明
information_schema
データベース名やテーブル名、列のデータ型やアクセス権など、すべてのデータベースに関する情報(メタデータ)メタデータが保存されている情報データベース
mysql
コアデータベースは、主にデータベースのユーザー、権限の設定、キーワードなどを保存し、使用する制御と管理情報を削除することはできません.
performance_schema
パフォーマンス最適化データベース、mysql 5.5バージョンに追加されたパフォーマンスに優れたエンジン
sys
システムデータベース、mysql 5.7バージョンに追加されたメタデータ情報を迅速に理解できるシステムライブラリは、データベースの多様な情報を発見しやすく、パフォーマンスのボトルネックの問題を解決します.
データベース関連アクション
create database mydb1;#
create database mydb2 character set gbk;
create database if not exists mydb4;# mydb4 ,
show create database mydb2;
alter database mydb2 character set gbk;
drop database mydb1;
show warnings;
select database();
use mysql;
3、データ照会、DML操作
データベース・テーブルの基本構造
リレーショナル構造のデータベースはテーブル(table)でデータ格納され、テーブルは行と列グループによって格納されます.
経験:クエリー文を実行して返される結果セットは仮想テーブルです.
基本クエリー
構文selectカラム名fromテーブル名
キーワードの説明
selectクエリーするテーブルを指定
fromはクエリーするテーブルを指します
#
create database companydb character set utf8;
#
select employee_id,first_name,email from t_employees;
#
# *
select * from T_employees;
#
select from t_employees;
select * from t_employees;
: , ,* , , 。
select employee_id,first_name,salary*12 from t_employees;
# + - * /
:% ,
as ' '
# , , ( )
select employee_id as ' ',first_name as ' ',salary*12 as ' ' from t_employees;
#
Select distininct manager_id from t_employees;
#
select from order by ,[ ]
asc
desc
# , , 。
select employee_id,first_name,salary from t_employees order by salary desc;
select employee_id,first_name,salary from t_employees order by salary desc,employee_id asc ;
select from where
where : , , 。
(=)
# 110000 ( , , )
select employee_id ,first_name,salary from t_employees where salary = 11000;
: java (==),mysql =
(and , or ,and )
110000 0.30 ( , , )
select employee_id,first_name,salary from T_employees
where salary = 110000 and commission_pct = 0.03;
select employee_id,first_name,salary from T_employees
where salary = 110000 or commission_pct = 0.03;
select employee_id,first_name,salary from T_employees
where not salary = 110000 or commission_pct = 0.03;
(> ,< ,>=,<=,!=,<>) != <>
select employee_id ,first_name,salary from t_employees
where salary >=600 and salary <=1000;
6000~10000 ( , , )
select employee_id,first_name,salary
from t_employees
where salary between 6000 and 1000;# , ,
null (is null,is not null)
null
select * from employees where commission is null;
select * from employees where commission is not null;
(in( 1, 2, 3))
# 70,80,90 ( , , , )
select employ_id ,first_name,salary,department_id
from t_employees
where department_id in (70,80,90,100)
select employ_id ,first_name,salary,department_id
from t_employees
where department_id = 70 or department_id =80 or department_id =90 or department_id =100
like _
Like ' ——'
like %
Like ' %'
:
case
when 1 then 1
when 1 then 2
when 3 then 3
else
end
, case end ,
: java switch
# ( , , , )( )
select employee_id,first_name,salary,department_id
case
when salary >=10000 then 'A'
when salary >=800 and salary <10000 the 'B'
when salary >6000 and salary <8000 then 'c'
when salary >=4000 and salary <6000 then 'D'
else 'E'
end as ' '
from employees
select [ ]
: , ( )
sysdate() ( , , , , , )
curdate()
curtime()
week(date)
year(date)
hour(time)
minute(time)
datediff(date1,date2) date1 date2
ADDDATE(DATE,N) date N
select 【 】
select concat(str1,str2,str)
insert(str,pos,len,newStr) str pos len newstr
lower(str)
upper(str)
substring(str,num,len) str num len , 1
select ( ) from
, ,
sum
avg
max
min
count
null , null
, null ,
select from where group by
count
(count)
select department_id ,count(employ_id) from t_employees
group by department_id;
:
# id, ,first_name
select department_id,count(*) first_name from t_employees
from t_employees group by department_id;
# : ,select , ,
:select from where group by having
having
select department_id max(salary)
from t_employees group by department_id
having department_id in (60,70,90)
,
select from limit ,
: 0 , , ,
, 10
Select * from t_employees limit 3,10
4、サブクエリ(条件判断として)
select from where
bureu
select * from employess where salary >= (select salary from employss where employss_name='brue')
# : ,
#
( )
select * from employess where name in (select last_name )
### ,
all
any
, , any all
select * form (select empid,employ from employess order by empid)
# ,
# , ,
select * from 1 Union all select * from 2
select *from 1 union select * from 2
( )
select * from t1 union select * from t2
;
: , ,
, union , 。
#
select from 1 2 on
inner join on
# ( ) sql
select * from t_employees innner join t_jobs t_employees.job_id = t_jobs.job_id;
# ( ) mysql
select * from t_employees ,t_jobs where t_employees.job_id = t_jobs.job_id;
: mysql , , sql
sql , 。
,
select * from t_employees e
inner join t_department d
on a.department_id = d.department_id
inner join t_localtion l
on d.location_id = l.localtion_id
left join on
# , , , , null
select e.employee_id,e.first_name,e.salary,d.department_name from t_employees e
left join t_departments d
on e.department_id = d.department_id
: , , ,
, null
: , , , ,
, null
5、DML操作
新規作成
Insert intoテーブル名(カラム名)values(値1,値2)
6、SQL言語分類