mysql 命令列增刪改查

來源:互聯網
上載者:User

標籤:

1.mysql資料庫的串連與關閉

串連資料庫:

mysql -h 伺服器主機地址 -u 使用者名稱 -p密碼

關閉串連:

在任何時候輸入exit或quit

2.建立新使用者並授權

grant 許可權 on 資料庫.資料表 to 使用者名稱@登入主機 identified by "密碼"

**登入主機是指定允許哪個主機登入,一般為了安全,就設為本地localhost

**許可權包括增刪改查  select insert delete update

例:grant all privileges on book.books to [email protected] identified by "12345"

添加一個新使用者zhang,密碼為123456,他可以在本地登入,並只對book資料庫的books表有所有的許可權。

3.建立資料庫

 create database book; 建立資料庫book

 drop database book;刪除資料庫book

show databases; 顯示所有已建立的資料庫

use book; 開啟book資料庫以當前資料庫使用

4.建立資料表

 create table person (

    -> id int NOT NULL AUTO_INCREMENT,
   -> PRIMARY KEY(id),
   -> username varchar(20),
   -> password varchar(20),
   -> Age int
   -> );

desc person; 查看當前表結構

5.向mysql資料庫表插入行記錄

兩種形式:

insert into person values(null,‘zhang‘,‘123456‘,20);

insert into person(id,username,password,Age) values(6,‘haha‘,‘123456‘,18);

6.從資料表中查詢資料記錄

select id,username,password,Age from person;

select * from person;

7.更改資料庫表中存在的記錄

update person set Age=15 where id=1;

 update person set username="zzzz" where username=‘haha‘;

等等有很多方法,只要是能唯一標識的都行。

8.刪除資料庫表中的記錄

delect from person where id=6;

等等有很多方法,只要是能唯一標識的都行。

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.