標籤:
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 命令列增刪改查