2018-07-14-mysql-库的基本操作.

2018-07-14  本文已影响0人  mychineseheart

库的基本操作

         1、查看已有的库

            show databases;

         2、创建库(指定字符集,默认字符集为Latin1)

            create database库名defaultcharset=utf8;

         3、查看创建库的语句

            show create database库名;

         4、查看当前所在的库

            select database();

         5、切换库

            use库名;

         6、查看库中已有的表

            show tables;

         7、删除库

            drop database库名;

实际操作.

mysql> show databases;

+--------------------+

| Database          |

+--------------------+

| information_schema |

| bd1                |

| bd2                |

| guo                |

| mysql              |

| performance_schema |

| studb              |

| studb1            |

| student_info      |

| sys                |

+--------------------+

10 rows in set (0.00 sec)

mysql>

mysql> create database GeXiaorui default charset=utf8;

Query OK, 1 row affected (0.00 sec)

mysql> show create database GeXiaorui;

+-----------+--------------------------------------------------------------------+

| Database  | Create Database                                                    |

+-----------+--------------------------------------------------------------------+

| GeXiaorui | CREATE DATABASE `GeXiaorui` /*!40100 DEFAULT CHARACTER SET utf8 */ |

+-----------+--------------------------------------------------------------------+

1 row in set (0.00 sec)

mysql>

mysql> select database();

+------------+

| database() |

+------------+

| NULL      |

+------------+

1 row in set (0.00 sec)

mysql> use GeXiaorui

Database changed

mysql> select database();

+------------+

| database() |

+------------+

| GeXiaorui  |

+------------+

1 row in set (0.00 sec)

mysql> show tables;

Empty set (0.00 sec)

mysql> drop database GeXiaorui

mysql> show databases;

    ->

tarena@tedu:~$ mysql -hlocalhost -uroot -p123456

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select database();

+------------+

| database() |

+------------+

| NULL      |

+------------+

1 row in set (0.00 sec)

mysql> drop database GeXiaorui;

Query OK, 0 rows affected (0.02 sec)

mysql> show databases;

+--------------------+

| Database          |

+--------------------+

| information_schema |

| bd1                |

| bd2                |

| guo                |

| mysql              |

| performance_schema |

| studb              |

| studb1            |

| student_info      |

| sys                |

+--------------------+

10 rows in set (0.00 sec)

mysql> create database GeXiaorui default charset=utf8;

Query OK, 1 row affected (0.00 sec)

mysql> show databases;

+--------------------+

| Database          |

+--------------------+

| information_schema |

| GeXiaorui          |

| bd1                |

| bd2                |

| guo                |

| mysql              |

| performance_schema |

| studb              |

| studb1            |

| student_info      |

| sys                |

+--------------------+

11 rows in set (0.00 sec)

mysql>

黑客帝国.
上一篇下一篇

猜你喜欢

热点阅读