標籤:tables style http dump describe str databases arch int
Linux下mysql的常用操作:
- 顯示資料庫
show databases;
- 選擇資料庫
use 資料庫名;
- 顯示資料庫中的表
show tables;
- 顯示資料表的結構
describe 表名;
- 顯示表中的記錄
SELECT * FROM 表名
- 建庫
create databse 庫名;
- 建表
create table 表名 (欄位設定列表);mysql> create table name( -> id int auto_increment not null primary key , -> uname char(8), -> gender char(2), -> birthday date );Query OK, 0 rows affected (0.03 sec)mysql> show tables;+------------------+| Tables_in_userdb |+------------------+| name |+------------------+1 row in set (0.00 sec)mysql> describe name;+----------+---------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+----------+---------+------+-----+---------+----------------+| id | int(11) | NO | PRI | NULL | auto_increment || uname | char(8) | YES | | NULL | || gender | char(2) | YES | | NULL | || birthday | date | YES | | NULL | |+----------+---------+------+-----+---------+----------------+4 rows in set (0.00 sec)註: auto_increment 自增 primary key 主鍵
- 增加記錄
insert into name(uname,gender,birthday) values(‘張三‘,‘男‘,‘1971-10-01‘);
- 修改記錄
update name set birthday=‘1971-01-10‘ where uname=‘張三‘;
- 刪除記錄
delete from name where uname=‘張三‘;
- 刪除表
drop table 表名
- 刪除庫
drop database 庫名;
- 備份資料庫
mysqldump -u root -p --opt 資料庫名>備份名; //進入到庫目錄
- 恢複
mysql -u root -p 資料庫名<備份名; //恢複時資料庫必須存在,可以為空白資料庫
原文: http://www.cnblogs.com/xdpxyxy/archive/2012/11/16/2773662.html
Linux下mysql的常用操作