命令列客戶端MySQL的使用

2021-10-10 17:29:59 字數 3042 閱讀 8891

登入資料庫

mysql -uroot -ppassword
登入成功後, 輸入如下命令檢視效果:

# 顯示當前時間

select now();

登出(退出)資料庫:

quit 或 exit 或 ctrl + d
檢視所有資料庫

show databases;
建立資料庫

create database 資料庫名 charset=utf8;

例:create database python charset=utf8;

使用資料庫

use 資料庫名;
檢視當前使用的資料庫

select database();
檢視創庫sql語句

show create database 資料庫名;

例:show create database mytest;

刪除資料庫(慎重)

drop database 資料庫名;

例:drop database python;

檢視當前資料庫中所有表

show tables;
建立表

create table students(

id int unsigned primary key auto_increment not null,

name varchar(20) not null,

age tinyint unsigned default 0,

height decimal(5,2),

gender enum('男','女','人妖','保密')

);

說明:

create table 表名(

欄位名稱 資料型別 可選的約束條件,

column1 datatype contrai,

...);

修改表-新增字段

alter table 表名 add 列名 型別 約束;

例:alter table students add birthday datetime;

修改表-修改字段型別

alter table 表名 modify 列名 型別 約束;

例:alter table students modify birthday date not null;

說明:

alter table 表名 change 原名 新名 型別及約束;

例:alter table students change birthday birth datetime not null;

說明:

修改表-刪除字段

alter table 表名 drop 列名;

例:alter table students drop birthday;

檢視創表sql語句

show create table 表名;

例:show create table students;

刪除表

drop table 表名;

例:drop table students;

查詢所有列

select * from 表名;

例:select * from students;

查詢指定列

select 列1,列2,... from 表名;

例:select id,name from students;

全列插入:值的順序與表結構欄位的順序完全一 一對應

insert into 表名 values (...)

例:insert into students values(0, 'xx', default, default, '男');

部分列插入:值的順序與給出的列順序對應

insert into 表名 (列1,...) values(值1,...)

例:insert into students(name, age) values('王二小', 15);

全列多行插入

insert into 表名 values(...),(...)...;

例:insert into students values(0, '張飛', 55, 1.75, '男'),(0, '關羽', 58, 1.85, '男');

部分列多行插入

insert into 表名(列1,...) values(值1,...),(值1,...)...;

例:insert into students(name, height) values('劉備', 1.75),('曹操', 1.6);

說明:

update 表名 set 列1=值1,列2=值2... where 條件

例:update students set age = 18, gender = '女' where id = 6;

delete from 表名 where 條件

例:delete from students where id=5;

-- 新增刪除表示字段,0表示未刪除 1表示刪除

alter table students add isdelete bit default 0;

-- 邏輯刪除資料

update students set isdelete = 1 where id = 8;

說明:

HDFS的shell 命令列客戶端 操作

cat ignorecrc checksum chgrp r group path.chmod r path.chown r owner group path.copyfromlocal f p copytolocal p ignorecrc crc count q cp f p createsna...

命令列客戶端中的SQL語句

命令列客戶端 1.進入mysql的bin目錄 cd c program files x86 mysql mysql server 5.1 bin 2.連線mysql mysql uroot p123456 用的時候不要直接輸密碼,一般先 mysql uroot p 然後回車 再輸入密碼 3.檢視所有...

Hadoop之hdfs命令列客戶端的常用操作命令

檢視hdfs中的目錄資訊 hadoop fs ls hdfs路徑 hadoop fs ls 建立資料夾 hadoop fs mkdir hdfs路徑 hadoop fs mkdir aaa 移動檔案或重新命名 hadoop fs mkdir hdfs路徑 hdfs路徑 hadoop fs mv aa...