1.创建数据库mysqlgt; create database if not exists tongcheng; query ok, 1 row affected (0.01 sec) mysqlgt; 2.查看创建数
1.创建数据库
mysql> create database if not exists tongcheng;
query ok, 1 row affected (0.01 sec)
mysql>
2.查看创建数据库时的选项
mysql> show create database tongcheng;
+-----------+----------------------------------------------------------------------+
| database | create database |
+-----------+----------------------------------------------------------------------+
| tongcheng | create database `tongcheng` /*!40100 default character set latin1 */ |
+-----------+----------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql>
3.连接数据库
mysql> use tongcheng;
database changed
mysql>
4.查看当前的数据库
mysql> select database();
+------------+
| database() |
+------------+
| tongcheng |
+------------+
1 row in set (0.01 sec)
mysql>
5.显示所有数据库
mysql> show databases;
+--------------------+
| database |
+--------------------+
| information_schema |
| mysql |
| test |
| tongcheng |
+--------------------+
4 rows in set (0.00 sec)
mysql>
6.修改数据库的属性
mysql> alter database tongcheng character set gbk;
query ok, 1 row affected (0.00 sec)
mysql>
7.删除数据库
mysql> drop database if exists tongcheng;
query ok, 0 rows affected (0.02 sec)
mysql>
8.用mysqladmin创建数据库
123 [root@localhost ~]# mysqladmin create tongcheng -u root -p
enter password:
[root@localhost ~]#
9.用mysqlshow查看数据库
[root@localhost ~]# mysqlshow -u root -p tongcheng
enter password:
database: tongcheng
+--------+
| tables |
+--------+
+--------+
[root@localhost ~]#
10.用mysqlshow查看数据库有多少表
[root@localhost ~]# mysqlshow -u root -p tongcheng
enter password:
database: tongcheng
+--------+
| tables |
+--------+
| t |
+--------+
[root@localhost ~]#
11.用mysqlshow查看数据库中表的信息
[root@localhost ~]# mysqlshow -u root -p tongcheng t
enter password:
database: tongcheng table: t
+-------+---------+-----------+------+-----+---------+-------+---------------------------------+---------+
| field | type | collation | null | key | default | extra | privileges | comment |
+-------+---------+-----------+------+-----+---------+-------+---------------------------------+---------+
| a | int(11) | | yes | | | | select,insert,update,references | |
+-------+---------+-----------+------+-----+---------+-------+---------------------------------+---------+
[root@localhost ~]#
12.用mysqlshow查看数据库中表的索引信息
[root@localhost ~]# mysqlshow -u root -p -k tongcheng t
enter password:
database: tongcheng table: t
+-------+---------+-----------+------+-----+---------+-------+---------------------------------+---------+
| field | type | collation | null | key | default | extra | privileges | comment |
+-------+---------+-----------+------+-----+---------+-------+---------------------------------+---------+
| a | int(11) | | yes | mul | | | select,insert,update,references | |
+-------+---------+-----------+------+-----+---------+-------+---------------------------------+---------+
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| table | non_unique | key_name | seq_in_index | column_name | collation | cardinality | sub_part | packed | null | index_type | comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| t | 1 | in_tong | 1 | a | a | | | | yes | btree | |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
[root@localhost ~]#
