mysql 21 條基本命令

1 . 查看 mysql 版本信息

mysqladmin --version

2 . 在 mysql 里運行可顯示出當前服務器版本。

SELECT VERTION();

3 . 輸入密碼即可連接到數(shù)據(jù)庫

mysql -u root -p

4 . 檢查 mysql 服務器是否啟動,啟動就會有 mysql 的進程列表

ps -ef | grep mysqld

5 . 新建一個數(shù)據(jù)庫。

CREATE DATABASE t1;

6 . 顯示所有數(shù)據(jù)庫。

SHOW DATABASES;

7 . 刪除數(shù)據(jù)庫。

DROP DATABASE t1;

8 . 選擇數(shù)據(jù)庫

use t1;

9 . 修改 root 用戶密碼。

mysqladmin -u root -p password 新密碼

10 . 選擇數(shù)據(jù)庫后創(chuàng)建數(shù)據(jù)表

create table user( sex char(4) not null);

sex 是列名,char(4) 是列的數(shù)據(jù)類型,not null 說明剛列的類型不能為空,默認的話是可以為空。

注意:至少要有一項
11 . 顯示數(shù)據(jù)庫表

SHOW TABLES;

12 . 查看數(shù)據(jù)庫表詳細信息

describe 表名;

13 . 向表中插入數(shù)據(jù)

  • 插入的是表中的列的值。
insert into student values("chen","male","135");

  • 插入部分 表名后面+(列名)再加值。
insert into student(na) values("pan");

14 . 查找表中數(shù)據(jù)

  • 查找表 student 中的所有列為 sex 的值。
select sex from student;
  • *表示查找所有內(nèi)容。
select * from student;
  • 按特定條件查詢,比如說查詢 sex = ma 。
select * from student where sex="ma";
  • 查詢年齡大于50的
select * from student where age > 50;
  • 查詢id小于5且年齡大于20的所有人信息:
select * from students where id<5 and age>20;

15 . 更改表中數(shù)據(jù)

update 表名稱 set 列名稱=新值 where 更新條件;

upadate student set tel = 110 where na = "pan";

16 . 刪除表的數(shù)據(jù)

  • delete from 表名稱 where 刪除條件;
delete from student where tel = "110";
  • 刪除表中所有數(shù)據(jù)
delete from student;

17 . 添加列

alter table 表名 add 列名 列數(shù)據(jù)類型;

18 . 修改列

alter table 表名 change 列名稱 列新名稱 新數(shù)據(jù)類型;

19 . 刪除列

alter table 表名 drop 列名稱;

20 . 重命名表

alter table 表名 rename 新表名;

21 . 刪除整張表

drop tabel 表名;

參考資料:
21 分鐘 MySQL 入門教程

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

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