建立数据库我们可以很多的方式来创建了,小编来为各位介绍使用命令行建立Mysql数据库的例子,希望例子对各位有帮助,命令行下建立不同字符集的数据库、删除数据库:
- [root@lamp~]#/usr/local/mysql/bin/mysql-uroot-p'admin123'
- Warning:Usingapasswordonthecommandlineinterfacecanbeinsecure.
- WelcometotheMySQLmonitor.Commandsendwith;or\g.
- YourMySQLconnectionidis2
- Serverversion:5.6.16Sourcedistribution
- Copyright(c)2000,2014,Oracleand/oritsaffiliates.Allrightsreserved.
- mysql>createdatabasebyrd_default;#建议一个叫做byrd_default的数据库
- QueryOK,1rowaffected(0.08sec)
- mysql>showdatabaseslike'byrd%';#查看以byrd开头的数据库,
- +------------------+
- |Database(byrd%)|
- +------------------+
- |byrd_default|
- +------------------+
- 1rowinset(0.00sec)
- mysql>showcreatedatabasebyrd_default;#查看系统建立byrd_default命令,byrd_default默认编码是utf8,因为我编译mysql的时候设置的默认编码为utf8
- +--------------+-----------------------------------------------------------------------+
- |Database|CreateDatabase|
- +--------------+-----------------------------------------------------------------------+
- |byrd_default|CREATEDATABASE`byrd_default`/*!40100DEFAULTCHARACTERSETutf8*/|
- +--------------+-----------------------------------------------------------------------+
- 1rowinset(0.00sec)
- mysql>createdatabasegbkdefaultcharactersetgbkcollategbk_chinese_ci;#建立一个名字叫做gbk,编码方式是gbk的数据库
- QueryOK,1rowaffected(0.00sec)
- mysql>showcreatedatabasegbk;
- +----------+-------------------------------------------------------------+
- |Database|CreateDatabase|
- +----------+-------------------------------------------------------------+
- |gbk|CREATEDATABASE`gbk`/*!40100DEFAULTCHARACTERSETgbk*/|
- +----------+-------------------------------------------------------------+
- 1rowinset(0.00sec)
- mysql>showdatabases;#所有数据库表
- +--------------------+
- |Database|
- +--------------------+
- |information_schema|
- |byrd_default|
- |gbk|
- |gbk1|
- |gbk2|
- |gbk3|
- |gbk4|
- |mysql|
- |performance_schema|
- |test|
- |ultrax|
- +--------------------+
- 11rowsinset(0.00sec)
- mysql>dropdatabasegbk1;#删除名字为gbk1的数据库
- QueryOK,0rowsaffected(0.19sec)--phpfensi.com
- mysql>dropdatabasegbk2;
- QueryOK,0rowsaffected(0.00sec)
- mysql>dropdatabasegbk3;
- QueryOK,0rowsaffected(0.00sec)
- mysql>dropdatabasegbk4;
- QueryOK,0rowsaffected(0.01sec)
- mysql>showdatabases;
- +--------------------+
- |Database|
- +--------------------+
- |information_schema|
- |byrd_default|
- |gbk|
- |mysql|
- |performance_schema|
- |test|
- |ultrax|
- +--------------------+
- 7rowsinset(0.00sec)
- mysql>dropdatabaseifexistsbyrd_default;#如果byrd_default的数据库存在则删除,如果不存在则提示警告
- QueryOK,0rowsaffected(0.00sec)
- mysql>showdatabases;
- +--------------------+
- |Database|
- +--------------------+
- |information_schema|
- |gbk|
- |mysql|
- |performance_schema|
- |test|
- |ultrax|
- +--------------------+
- 6rowsinset(0.00sec)
- mysql>