其实对很多人来说对于SQL语句已经忘了很多,或者说是不懂很多,因为有数据库图形操作软件,方便了大家,但是我们不能忘记最根本的东西,特别是一些细节上的东西,可能你用惯了Hibernate,不用写SQL语句,但是不是任何项目都要用到大框架的,如果不用,那你是不是就不会操作数据库了呢,所以我们最好还是熟悉一点好,对我们以后找工作和工作都有帮助。
在说创建、修改和删除表前,我们还是要进行一个操作的简单说明:
1.登陆数据库系统
在命令行中登陆MySQL数据库管理系统,输入一下内容:
mysql -h localhost -u root -p
很多人都知道这个,但是其中参数的具体表示什么我们还是要了解的,其中,“-h”参数指连接的主机名,所以后面是localhost;“-u”参数表示用户名,此处的用户名为root;“-p”参数表示用户的密码,按下Enter键后就显示“Enter password:”,输入密码即可登录进去了。
2.创建数据库
在创建数据库之前,我们可以查看已经存在的数据库:
mysql>SHOW DATABASES;+--------------------+
| Database |
+--------------------+
| information_schema |
| community |
| community_test |
| data |
| mydata |
| mysql |
| performance_schema |
| test |
+--------------------+
8 rows in set (0.04 sec)
创建数据库的格式:CREATE DATABASE 数据库名;
示例:创建一个名为example的数据库
mysql> CREATE DATABASEexample;
Query OK,1 row affected (0.00sec)
mysql>SHOW DATABASES;+--------------------+
| Database |
+--------------------+
| information_schema |
| community |
| community_test |
| data |
| example |
| mydata |
| mysql |
| performance_schema |
| test |
+--------------------+
9 rows in set (0.00 sec)
3.删除数据库:
格式:DROP DATABASE 数据库名;
示例:删除example数据库
mysql> DROP DATABASEexample;
Query OK,0 rows affected (0.07sec)
mysql>SHOW DATABASES;+--------------------+
| Database |
+--------------------+
| information_schema |
| community |
| community_test |
| data |
| mydata |
| mysql |
| performance_schema |
| test |
+--------------------+
8 rows in set (0.00 sec)
4.数据库存储引擎
存储引擎就是指表的类型,数据库存储引擎决定了表在计算机的存储方式。
MySQL中查询存储引擎的类型命令:SHOW ENGINES;
mysql>SHOW ENGINES;+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine | Support |Comment| Transactions | XA | Savepoints |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
| FEDERATED | NO |Federated MySQL storage engine| NULL | NULL | NULL |
| MRG_MYISAM | YES | Collection ofidentical MyISAM tables| NO | NO | NO |
| MyISAM | YES |MyISAM storage engine| NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write toit disappears)| NO | NO | NO |
| CSV | YES |CSV storage engine| NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful fortempor
ary tables| NO | NO | NO |
| ARCHIVE | YES |Archive storage engine| NO | NO | NO |
| InnoDB | DEFAULT | Supports transactions, row-level locking, andf
oreign keys| YES | YES | YES |
| PERFORMANCE_SCHEMA | YES | Performance Schema
| NO | NO | NO |
+--------------------+---------+----------------------------------------------------------------+--------------+------+------------+
9 rows in set (0.00 sec)
查询结果中,Engine参数指存储引擎名称;Support参数说明MySQL是否支持该类型引擎;Comment参数表示对该引擎的评论