開発しなければならない-mysqlコマンド

データ定義文、データ操作文と制御文のデータ、ベースMysql5.7をカバーする開発者に必要なMySQLの一般的なコマンド、。

データ定義言語(DDL)

データベース操作

  • ログデータベース:
mysql -uroot -proot
  • データベースを作成します。
create database test
  • すべてのデータベースを表示します。
show databases

IMG

  • データベースと使用を選択します。
use test
  • すべてのデータの表を参照してください。
show tables
  • データベースを削除します。
drop database test

手術台

  • テーブルを作成します。
create table emp(ename varchar(10),hiredate date,sal decimal(10,2),deptno int(2))  
create table dept(deptno int(2),deptname varchar(10))

IMG

  • テーブル定義を表示します。
desc emp

IMG

  • テーブル定義(詳細を)見ます:
show create table emp \G

IMG

  • 表を削除します。
drop table emp
  • テーブルのフィールドを変更します。
alter table emp modify ename varchar(20)
  • テーブルのフィールドを追加します:
alter table emp add column age int(3)
  • テーブルのフィールドを削除します。
alter table emp drop column age
  • 名前を変更した場;
alter table emp change age age1 int(4)
  • テーブル名を変更します。
alter table emp rename emp1

データ操作文(DML)

レコードの挿入

  • 挿入された名前を指定します。
insert into emp (ename,hiredate,sal,deptno) values ('zhangsan','2018-01-01','2000',1)
  • 挿入された名前を指定しないでください。
insert into emp values ('lisi','2018-01-01','2000',1)
  • 一括挿入データ:
insert into dept values(1,'dept1'),(2,'dept2')

レコードを変更します。

update emp set sal='4000',deptno=2 where ename='zhangsan'

レコードの削除

delete from emp where ename='zhangsan'

検索履歴

  • すべてのレコードを照会します。
select * from emp
  • クエリがレコードを複製しません。
select distinct deptno from emp
  • 条件のお問い合わせ:
select * from emp where deptno=1 and sal<3000
  • ソートと制限:
select * from emp order by deptno desc limit 2
  • ページングクエリ(10の記録を開始するために0からの問合せ):
select * from emp order by deptno desc limit 0,10
  • 重合(セクタの数は、セクタ問い合わせ番号1より大きい)。
select deptno,count(1) from emp group by deptno having count(1) > 1
  • クエリに参加:
select * from emp e left join dept d on e.deptno=d.deptno
  • サブクエリ:
select * from emp where deptno in (select deptno from dept)
  • 合同記録:
select deptno from emp union select deptno from dept

データ制御文(DCL)

関連当局

  • 確かに操作権限(すべてのテーブルへのテストユーザーテスト・データベースを選択し、挿入権限を付与するには):
grant select,insert on test.* to 'test'@'localhost' identified by '123'
  • ビューアカウントの権限:
show grants for 'test'@'localhost'

IMG

  • 操作権限の回復:
revoke insert on test.* from 'test'@'localhost'

IMG

  • すべてのデータベースに付与されたすべての権限:
grant all privileges on *.* to 'test'@'localhost'
  • (補助金を含む)すべてのデータベースに付与されたすべての権限:
grant all privileges on *.* to 'test'@'localhost' with grant option
  • SUPERプロセスファイル許可権限(データベース・システム権限を指定することはできません)。
grant super,process,file on *.* to 'test'@'localhost'
  • だけにログオンする権限を付与されました:
grant usage on *.* to 'test'@'localhost'

アカウント関連

  • アカウントを削除します。
drop user 'test'@'localhost'
  • パスワードを変更します。
set password = password('123')
  • 他の誰かパスワードによって変更管理者:
set password for 'test'@'localhost' = password('123')

他の

文字は関連を設定します。

  • 表示文字セット:
show variables like 'character%'

IMG

  • データベースを作成するときに文字セットを指定します。
create database test2 character set utf8

IMG

時間帯

  • 現在のタイムゾーン表示(世界のためにUTC統一された時間を、中国はUTC + 8です):
show variables like "%time_zone%"

IMG

  • あなたがグローバルゾーンを変更するとGMTのMySQLは、我々は東エリア8住んでいること、です。
set global time_zone = '+8:00';
  • 現在の会話エリアを変更します。
set time_zone = '+8:00'http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/blog/refer_screen_50.png
  • すぐに効果的な:
flush privileges

おすすめ

転載: www.cnblogs.com/guoyinghome/p/11220263.html