1)在數(shù)據(jù)庫中創(chuàng)建一個(gè)數(shù)據(jù)表 樣例: CREATE TABLE IF NOT EXISTS table_name ( field1 datatype, field2 datatype, field3 datatype )[CHARACTER SET 字符集 COLLATE 校對規(guī)則];
2)選擇相應(yīng)的數(shù)據(jù)庫 eg: use databases_name; 3)查看當(dāng)前數(shù)據(jù)庫 SELECT DATABASE(); 4)創(chuàng)建表 mysql> CREATE TABLE IF NOT EXISTS user( -> id int, -> name varchar(20), -> password varchar(20), -> birthday date -> ); Query OK, 0 rows affected (0.01 sec) mysql> mysql> mysql> SHOW TABLES; +-----------------+ | Tables_in_mydb1 | +-----------------+ | user | +-----------------+ 1 row in set (0.00 sec) 5)查看數(shù)據(jù)庫中的表 SHOW TABLES;
mysql> CREATE TABLE IF NOT EXISTS employee( -> id int, -> name varchar(20), -> gender varchar(20), -> birthday date, -> entry_date date, -> job varchar(20), -> salary float(8,2), -> resume text -> ); Query OK, 0 rows affected (0.02 sec) 6)查看數(shù)據(jù)庫中已經(jīng)創(chuàng)建好的表 mysql> SHOW TABLES; +-----------------+ | Tables_in_mydb1 | +-----------------+ | employee | | user | +-----------------+ 2 rows in set (0.00 sec) 7)查看新建表中的字段內(nèi)容 mysql> SHOW CREATE TABLE USER; +-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | USER | CREATE TABLE `user` ( `id` int(11) DEFAULT NULL, `name` varchar(20) DEFAULT NULL, `password` varchar(20) DEFAULT NULL, `birthday` date DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 | +-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) |
|