mysql 基礎語句

2021-10-16 09:03:50 字數 1547 閱讀 8176

檢視資料庫三種方式

show databases;

show databases \g

mysql -e 「show databases」 -uroot -p123 -a

建立資料庫

create database lck;

選擇要操作的資料庫

use database_name;

命令列選擇資料庫

mysql -uroot -p123 -a lck;

檢視所處位置

select database();

檢視當前時間

select now();

使用者select user();

刪除資料庫

if exists

drop database if exists lpl;

create database if not exists lpl;

建立表create table table_name(欄位名 字段型別);

檢視表show tables;

檢視建立錶用了哪些命令

show create table table_name;

檢視表具體結構

desc table_name;

刪除表drop table table_name;

修改表名

alter table tabl_name rename 新錶名;

修改表中字段型別

alter table table_name modify 欄位名 要修改的型別;

完整修改

alter table table_name change 欄位名 新欄位名 修改的型別;

表中新增字段

alter table table_name add 欄位名 字段型別;

刪除表中字段

alter table table_name drop 欄位名;

表中插入資料

insert into table_name values(值1,值2);

插入多條

insert into table_name values(),();

分開插入

insert into table_name(要插入的字段) values();

查詢表中資料

select * from table_name;

去重複查詢

select distinct 有重複的欄位名 from table_name;

區分大小寫查詢

select * from table_name where binary 欄位名=字段值:

查詢排序

select 欄位名 from table_name order by 欄位名 asc;

select 欄位名 from table_name order by 欄位名 desc;

刪除表中資料

delete from table_name where 欄位名=值;

更新表中資料

update table_name set 修改的欄位名=字段值 where 在那個字段 可以用and or

mysql5 0基礎語句 mysql基礎語句(一)

一 登入 退出 退出 quit 或 exit 二 備份 恢復資料庫 備份資料庫 在mysql服務外面執行 mysqldump h伺服器位址 u登入名 p 要備份的資料庫名 要儲存為的檔案 恢復資料庫 mysql h伺服器位址 u登入名 p埠號 p 資料庫名 注意 通常該資料庫名是需要先建立 存在 三...

mysql5 0基礎語句 MySQL基礎語句

檢視語句 檢視所有資料庫 show databases 檢視表結構 desc table name 檢視庫中所有表 show tables 檢視建表語句 show create table 新建表語句 新建表 id int unsigned not null auto increment comme...

mysql基礎語句

一.如何進入mysql 在window下面的cmd下 mysql help 將顯示所有的幫助資訊 mysql version 將顯示版本資訊 mysql host h 主機名 聯結到某個主機 localhost預設本地 mysql user u 使用者名稱 mysql password p 密碼 按...