1. 程式人生 > >Mysql常用操作語法彙總

Mysql常用操作語法彙總

Mysql命令列:

>mysql -u root -p
Enter password:******
Welcome to the MySQL monitor.  Commands end with ; or \g.
......
mysql>

# 檢視系統中的資料庫
mysql> show databases;
# 選擇某個要操作的資料庫
mysql> use dbname;
# 檢視改資料庫下的所有資料表
mysql> show tables;

# 檢視某張表的定義
mysql> desc tablename;
# 檢視某張表全面的定義資訊
mysql> show create table tablename;
# 刪除某張表
mysql> drop table tablename; # 修改表中欄位的資料型別 mysql> alter table tablename MODIFY colname new_coltype; # 增加表字段 mysql> alter table tablename ADD column colname coltype; # 刪除某個欄位 mysql> alter table tablename DROP column colname; # 欄位改名 mysql> alter table tablename CHANGE colname new_colname coltype; # 更改表名
mysql> alter table tablename RENAME new_tablename;