MySQL資料庫的基礎操作(建表,建庫,插入,刪除)

來源:互聯網
上載者:User

標籤:mysql

留給我健忘的記憶,希望他知道這裡還有一些記憶!!

下面將是以多執行個體模式登入資料庫然後建立一個庫並完成建表,插入資料,刪除資料,更新資料的操作。

1 登入資料庫

[[email protected] ~]# mysql -uroot -p123456 -S /data/3306/mysql.sock

650) this.width=650;" class="alignnone size-full wp-image-36" src="http://www.prozhi.com/wp-content/uploads/2015/07/11.png" alt="1" width="698" height="545" style="border:0px;height:auto;margin-bottom:12px;" />

2 建立資料庫,指定utf8字元集來支援中文,當然,如果你的資料庫編譯的時候已經指定預設字元集為utf8這裡就不需要再次指定了。

mysql> create database wodejia character set utf8 collate utf8_general_ci;

顯示建立庫時的參數

mysql> show create database wodejia;

650) this.width=650;" class="alignnone size-full wp-image-37" src="http://www.prozhi.com/wp-content/uploads/2015/07/21.png" alt="2" width="698" height="545" style="border:0px;height:auto;margin-bottom:12px;" />

 

如果不知道字元集的話可以用 show character set;  查看所有的字元集,如

msyql> show character set;

650) this.width=650;" class="alignnone size-full wp-image-38" src="http://www.prozhi.com/wp-content/uploads/2015/07/3.png" alt="3" width="698" height="545" style="border:0px;height:auto;margin-bottom:12px;" />

3 切換到剛剛建立的資料庫,然後建立一個簡單的表,(你可以把他理解為Excel表格…….)

mysql> create table `chengyuan` ( `id` int(4) not null, `姓名` char(20) not null, `性別` char(20) not null, `年齡` tinyint(2) not null, `愛好` char(20) not null, `其他` char(20) not null, primary key(id));

650) this.width=650;" class="alignnone size-full wp-image-39" src="http://www.prozhi.com/wp-content/uploads/2015/07/4.png" alt="4" width="698" height="545" style="border:0px;height:auto;margin-bottom:12px;" />

4 插入一行資料

mysql> insert into chengyuan(id,姓名,性別,年齡) values(1,‘楊仔‘,‘男‘,‘23‘);

650) this.width=650;" class="alignnone size-full wp-image-41" src="http://www.prozhi.com/wp-content/uploads/2015/07/51.png" alt="5" width="698" height="545" style="border:0px;height:auto;margin-bottom:12px;" />

 

5 同時插入多行資料

mysql> insert into chengyuan(id,姓名,性別,年齡) values(2,‘璐璐‘,‘女‘,‘21‘),(3,‘明明‘,‘男‘,‘21‘);

650) this.width=650;" class="alignnone size-full wp-image-42" src="http://www.prozhi.com/wp-content/uploads/2015/07/6.png" alt="6" width="698" height="545" style="border:0px;height:auto;margin-bottom:12px;" />

6 O fuck, 你發現愛好忘了填寫,好吧 我們用下面的這個命令來更新這條記錄

mysql> update chengyuan set 愛好=‘折騰‘ where id="1";

650) this.width=650;" class="alignnone size-full wp-image-43" src="http://www.prozhi.com/wp-content/uploads/2015/07/7.png" alt="7" width="698" height="545" style="border:0px;height:auto;margin-bottom:12px;" />

 

把其他兩個人的愛好也更新下

mysql>  update chengyuan set 愛好=‘吃‘ where id="2"; update chengyuan set 愛好=‘歡樂‘ where id="3";

650) this.width=650;" class="alignnone size-full wp-image-44" src="http://www.prozhi.com/wp-content/uploads/2015/07/8.png" alt="8" width="698" height="545" style="border:0px;height:auto;margin-bottom:12px;" />

7  我們來刪除一條記錄(把自己刪掉!!)

mysql> delete from chengyuan where id="1";

650) this.width=650;" class="alignnone size-full wp-image-45" src="http://www.prozhi.com/wp-content/uploads/2015/07/9.png" alt="9" width="698" height="545" style="border:0px;height:auto;margin-bottom:12px;" />

 

可以用下面的語句清空整個表:

mysql>delete from chengyuan;

 

好了 到這裡你應該已經學會資料庫的增刪改查(select 用了不知多少遍了我想你應該早記住了把)啦,以後忘了記得來這裡看看。。。。。。


本文出自 “陽的小窩” 部落格,請務必保留此出處http://shlinux.blog.51cto.com/6965661/1680715

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.