MySQL資料庫對資料庫的操作

來源:互聯網
上載者:User

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

13.用mysqladmin刪除資料庫
[root@localhost ~]# mysqladmin drop  tongcheng  -u root -p
Enter password:
Dropping the database is potentially a very bad thing to do.
Any data stored in the database will be destroyed.
Do you really want to drop the 'tongcheng' database [y/N] y
Database "tongcheng" dropped
[root@localhost ~]#

14.用mysqladmin關閉資料庫
[root@localhost ~]# mysqladmin  -u root -p shutdown
Enter password:
[root@localhost ~]#

  • 1
  • 2
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.