mysql的一些命令

mysql的一些命令:

連接mysql:mysql? -uroot -p,然后輸入密碼

退出登錄:quit或者exit

查看當(dāng)前版本:select? version();

心是當(dāng)前時間:select now();

遠(yuǎn)程連接:mysql -hip地址 -uroot -p;




創(chuàng)建數(shù)據(jù)庫:create database 數(shù)據(jù)庫名 charset=utf8;

刪除數(shù)據(jù)庫:drop database 數(shù)據(jù)庫名;

切換數(shù)據(jù)庫:use 數(shù)據(jù)庫名;

查看當(dāng)前選擇的數(shù)據(jù)庫:select database();

查看所有數(shù)據(jù)庫:show? databases;




查看當(dāng)前數(shù)據(jù)庫中所有表:show tables;

創(chuàng)建表:

auto_increment:表示自增長

創(chuàng)建數(shù)據(jù)表

alter table 表名 add|change|drop? 列名 類型;

舉個栗子:alter table students add birthday datetime;

刪除表:drop table 表名;

查看表結(jié)構(gòu):desc 表名;

更改表名:alter table 原表名 rename? 新表名? 新數(shù)據(jù)類型;

查看表的創(chuàng)建語句:show create table '表名';

查看表的所有內(nèi)容:select * from 表名;

全列插入:insert into 表名 values(...)

缺省插入:insert into 表名(列1,...) values(值1,...)

同時插入多條數(shù)據(jù):insert into 表名 values(...),(...)...;

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




數(shù)據(jù)備份:

sudo -s

cd/var/lid/mysql

mysql dump -uroot -p 數(shù)據(jù)庫名 >~/desktop/備份文件.sql;

修改字段的位置:

alter ?table ?表名 ?modify ?字段名 ?類型 ?first;

將字段名1放到字段名2的后面:

alter ?table ?表名 ?modify ?字段名1 ?字段類型 ?after ?字段名2;

更改存儲引擎:

alter table 表名 engine=存儲引擎名;

顯示搜索引擎:

show create table 表名\g;

刪除表的外鍵約束:

alter table 表名 drop foreign key 外鍵別名;

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容