登录  /  注册
MySQL数据库对数据库的操作
php中文网
发布: 2016-06-07 17:34:30
原创
716人浏览过

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 ~]#

来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 技术文章
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2023 //m.sbmmt.com/ All Rights Reserved | 苏州跃动光标网络科技有限公司 | 苏ICP备2020058653号-1

 | 本站CDN由 数掘科技 提供

登录PHP中文网,和优秀的人一起学习!
全站2000+教程免费学