mysql --- 创建数据库
Posted 从前慢
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql --- 创建数据库相关的知识,希望对你有一定的参考价值。
1、每创建一个数据库,在mysql的data文件夹里会创建一个目录,数据库名就是目录名
mysql> create database phone_num; Query OK, 1 row affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | phone_num | | sys | +--------------------+ 5 rows in set (0.00 sec)
查看data文件,有phone_num这个文件夹
cd /usr/local/mysql/data
[root@iz2zedr8770rctry7tq8t7z data]# ls
auto.cnf ib_buffer_pool ibdata1 ib_logfile0 ib_logfile1 ibtmp1 iz2zedr8770rctry7tq8t7z.pid mysql performance_schema phone_num sys
2、创建表
mysql> use phone_num Database changed mysql> create table phone_num_data -> (case_id INT(4) PRIMARY KEY, -> phone_num INT(11) ); Query OK, 0 rows affected (0.01 sec) mysql> show tables; +---------------------+ | Tables_in_phone_num | +---------------------+ | phone_num_data | +---------------------+ 1 row in set (0.00 sec)
3、查看表结构
mysql> desc phone_num_data ; +-----------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+---------+------+-----+---------+-------+ | case_id | int(4) | NO | PRI | NULL | | | phone_num | int(11) | YES | | NULL | | +-----------+---------+------+-----+---------+-------+ 2 rows in set (0.00 sec)
4、想更改数据库名,从1中可以知道,直接改文件名就可以啦
[root@iz2zedr8770rctry7tq8t7z data]# ls
auto.cnf ib_buffer_pool ibdata1 ib_logfile0 ib_logfile1 ibtmp1 iz2zedr8770rctry7tq8t7z.pid mysql performance_schema phone_num sys
[root@iz2zedr8770rctry7tq8t7z data]# mv phone_num test_cases
[root@iz2zedr8770rctry7tq8t7z data]# ls
auto.cnf ib_buffer_pool ibdata1 ib_logfile0 ib_logfile1 ibtmp1 iz2zedr8770rctry7tq8t7z.pid mysql performance_schema sys test_cases
改完啦,查询看看吧
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | | test_cases | +--------------------+ 5 rows in set (0.00 sec)
不要改了,改完就报错
mysql> desc phone_num_data; ERROR 1146 (42S02): Table ‘test_cases.phone_num_data‘ doesn‘t exist
5、
6、
以上是关于mysql --- 创建数据库的主要内容,如果未能解决你的问题,请参考以下文章