1.创建一个名叫 db_classes 的数据库:
创建一个叫 db_classes 的数据库MySQL命令:
create database db_classes;
运行效果:
show create database db_classes;
运行效果:
其他基础操作:
drop database db_classes; 删除数据库MySQL命令
show databases; 查询所有的数据库命令
alter database db1 character set gbk; 将数据库的字符集修改为gbk
use db1; 切换数据库
select database(); 查看当前使用的数据库
2.数据表的创建 :
mysql> use db_classes;
Database changed
mysql> show tables;
Empty set (0.01 sec)mysql> create table db_hero(-> id int not null,-> name varchar(100) not null,-> world varchar(100),-> );
Query OK, 0 rows affected (0.03 sec)mysql> desc db_hero;
+----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| id | int | NO | | NULL | |
| name | varchar(100) | NO | | NULL | |
| world | varchar(100) | YES | | NULL | |
+----------+--------------+------+-----+---------+-------+
9 rows in set (0.00 sec)
3.数据表的插入
mysql> insert into db_hero values(1,"孙悟空","西游记");
Query OK, 1 row affected (0.01 sec)mysql> insert into db_hero values(2,"林黛玉","红楼梦");
Query OK, 1 row affected (0.01 sec)mysql> insert into db_hero values(3,"宋江","水浒传");
Query OK, 1 row affected (0.00 sec)mysql> insert into db_hero values(4,"关羽","三国演义");
Query OK, 1 row affected (0.00 sec)mysql> insert into db_hero values(5,"白龙马","西游记");
Query OK, 1 row affected (0.00 sec)mysql> insert into db_hero values(6,"猪八戒","西游计");
Query OK, 1 row affected (0.00 sec)