时间:2021-07-01 10:21:17 帮助过:36人阅读
命令行登录数据库(mysql -uroot -p直接跟密码, 不带空格, 可以直接登录)
1 shell> mysql -ptest
2 shell> mysql -p test
3 第一个命令让mysql使用密码test,但没有指定默认数据库。第二个命令让mysql提示输入 密码并使用test作为默认数据库。
mysql -u root -p
输入密码
查看数据库列表
show databases
+--------------------+
| Database |
+--------------------+
| information_schema |
| cdcol |
| menagerie |
| mysql |
| phpmyadmin |
| roadofhonda |
| spring |
| test |
+--------------------+
8 rows in set (0.00 sec)
CREATE TABLE pet (
name VARCHAR(20),
owner VARCHAR(20),
species VARCHAR(20),
sex CHAR(1),
birth DATE,
death DATE
);
到mysql安装目录的data下去查看, 多了一个文件夹menagerie, 进入文件夹, 发现有这样几个文件
pet.frm 结构文件
pet.MYD 数据文件
pet.MYI 索引文件
查看创建表的信息
DESCRIBE pet
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| name | varchar(20) | YES | | NULL | |
| owner | varchar(20) | YES | | NULL | |
| species | varchar(20) | YES | | NULL | |
| sex | char(1) | YES | | NULL | |
| birth | date | YES | | NULL | |
| death | date | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
6 rows in set (0.02 sec)
Fluffy Harold cat f 1993-02-04 /N
Claws Gwen cat m 1994-03-17 /N
Buffy Harold dog f 1989-05-13 /N
Fang Benny dog m 1990-08-27 /N
Bowser Diane dog m 1979-08-31 1995-07-29
Chirpy Gwen bird f 1998-09-11 /N
Whistler Gwen bird /N 1997-12-09 /N
Slim Benny snake m 1996-04-29 /N
+----------+--------+---------+------+------------+------------+
| name | owner | species | sex | birth | death |
+----------+--------+---------+------+------------+------------+
| Fluffy | Harold | cat | f | 1993-02-04 | NULL |
| Claws | Gwen | cat | m | 1994-03-17 | NULL |
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
| Fang | Benny | dog | m | 1990-08-27 | NULL |
| Bowser | Diane | dog | m | 1979-08-31 | 1995-07-29 |
| Chirpy | Gwen | bird | f | 1998-09-11 | NULL |
| Whistler | Gwen | bird | NULL | 1997-12-09 | NULL |
| Slim | Benny | snake | m | 1996-04-29 | NULL |
+----------+--------+---------+------+------------+------------+
8 rows in set (0.00 sec)