標籤:進入 base char inux mysqld roo dump sql資料庫 linu
2.查詢
show databases; ##顯示資料庫
use mysql; ##進入mysql資料庫
show tables; ##顯示當前庫中表的名稱
select * from user; ##查詢user表中的所有內容
desc user; ##查詢user表的結構
3.資料庫以及表的建立
create database westos; ##建立westos資料庫
create table linux( ##建立表linux
username varchar(15) not null, ##username欄位,字元最大長度為15,且不為空白
password varchar(15) not null
);
insert into linux values (‘user1‘,‘passwd1‘); ##給linux表中添加資料
insert into linux values (‘user1‘,password(‘passwd1‘)); ##給linux表中添加資料,且密碼加密
4.更新資料庫資訊
update linux set password=password(‘passwd2‘) where username=‘user1‘; ##更新名字是user1的密碼
update linux set password=password(‘123‘) where (username=‘user1‘ or username=‘user2‘); ##更新user1,user2密碼
5.刪除資料庫
delete from linux where username=‘user1‘; ##從linux表中刪除user1使用者
drop table linux; ##刪除linux表
drop database westos; ##刪除westos資料庫
6.資料庫的備份
mysqldump -u root -pwestos --all-database ##備份所有表中的所有資料
mysqldump -u root -pwestos --all-database --no-date ##備份所有表,但不備份資料
mysqldump -u root -pwestos westos ##備份westos資料庫
mysqldump -u root -pwestos westos > /mnt/westos.sql ##備份westos庫,並將資料儲存到westos.sql檔案中
mysqldump -u root -pwestos westos linux > /mnt/linux.sql ##備份westos資料庫中的linux表
mysql -uroot -pwestos -e "create database westos;" ##還原資料時,應先建立相應的westos庫
mysql -uroot -pwestos westos < /mnt/westos.sql ##將資料匯入westos庫
mariadb資料庫簡單操作