Mysql資料庫的一些基本操作

來源:互聯網
上載者:User

標籤:ble   app   modify   cap   nbsp   insert   create   admin   where   

今天,終於把MySQL資料庫的知識系統的過了一遍,下面整理出一些常用的基本操作。

一、MySQL伺服器的啟動與關閉

1、啟動MySQL伺服器

開始 -> 運行   輸入“cmd”,然後在命令提示字元下輸入“net start MySQL”指令。

2、串連MySQL伺服器

輸入指令:MySQL -uroot  -h127.0.0.1 -p111(-h127.0.0.1看個人情況輸不輸)

註:使用者名稱為“root”,MySQL資料庫伺服器地址為“127.0.0.1”,密碼為“111”,三者之間必須有空格。

3、關閉MySQL伺服器

開始 -> 運行   輸入“cmd”,然後在命令提示字元下輸入“net stop MySQL”指令。

二、操作MySQL資料庫

1、建立資料庫

create database 資料庫名;

2、查看資料庫

show databases;

3、選擇指定資料庫

use 資料庫名;

4、刪除資料庫

drop database 資料庫名;

註:自動刪除MySQL安裝目錄中的“C:/AppServ/MySQL/data”檔案夾。

三、操作MySQL資料表

1、建立表

create table 表名 (column_name column_type not null,...)

create table語句的屬性說明
屬性 說明 屬性 說明
column_name 欄位名 Primary key 該列是否為主碼
column_type 欄位類型 AUTO_INCREMNT 該列是否自動編號
Not null | null 該列是否允許為空白    

 

 

 

 

建立資料表後,“C:\AppServ\MySQL\data\資料庫名\”中自動建立對應表檔案(“表名.frm”,“表名.MYD”,“表名.MYI”)

2、查看資料庫中的表

show tables;

3、查看資料庫中所有的表

show tables;(前提是使用use database 資料庫;)

4、查看資料表結構

describe 表名;

5、修改資料表結構

alter table 表名

  add [column] create_definition [first | after column_name]  //添加新欄位

  add primary key (index_col_name,...)  //添加主碼名稱

  alter [column] col_name {set default literal |rop default}  //修改欄位名稱

  change [column] old_col_name create_definition  //修改欄位名及類型

  modify [column] create_definition  //修改欄位類型

  drop [column] col_name  //刪除欄位

  drop primary key  //刪除主碼

  rename [as] new_tablename  //更改表名

eg:alter table Admin_Info

    drop A_Pwd,

    rename as Admin_Info2;

6、刪除指定資料表

drop table 表名;

四、操作MySQL資料

1、添加表資料

文法1:insert into 表名 values(值1,值2,...)(自增長的列應寫null)

文法2:insert into 表名(欄位1,欄位2,...) values (值1,值2,...)

文法3:insert into 表名 set 欄位1=值1,欄位2=值2,...

2、更新表資料

update 表名 set 欄位1=值1 where 查詢條件

若無查詢條件,表中所有資料行都會被修改。

3、刪除表資料

delete from 表名 where 查詢條件

若無查詢條件,表中所有資料行都會被刪除。

4、查詢表資料

select * from 表名;

5、限制查詢記錄數

select * from 表名 limit[start] length

start:表示從第幾行記錄開始輸出,0表示第1行

 

Mysql資料庫的一些基本操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.