库表曾删改查和存储引擎
Posted 随心朝阳
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了库表曾删改查和存储引擎相关的知识,希望对你有一定的参考价值。
一、数据库的增删改查
增:create database xiaoyu;
mysql> create database xiaoyu; Query OK, 1 row affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | | wordpress | | xiaoyu | +--------------------+ 6 rows in set (0.00 sec)
删:drop database xiaoyu;
mysql> drop database xiaoyu; Query OK, 0 rows affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | | wordpress | +--------------------+ 5 rows in set (0.00 sec) mysql>
改:alter database xiaoyu charset utf8;
mysql> alter database xiaoyu charset utf8; Query OK, 1 row affected (0.00 sec) mysql>
查:show create database xiaoyu;
mysql> show create database xiaoyu; +----------+-----------------------------------------------------------------+ | Database | Create Database | +----------+-----------------------------------------------------------------+ | xiaoyu | CREATE DATABASE `xiaoyu` /*!40100 DEFAULT CHARACTER SET utf8 */ | +----------+-----------------------------------------------------------------+ 1 row in set (0.04 sec) mysql>
查所有的数据库:show databases;
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | | wordpress | | xiaoyu | +--------------------+ 6 rows in set (0.00 sec)
二、表的增删改查
曾:create table member(id int,name char);
删:drop table member;
改:insert into member(id,name) values(1,‘y‘);
不写给谁传值就指定都传,而且还是按照位置传
查:show tables; #查看所有表
show create table t1;#查看指定的表 select * from t1 #查看表数据 select id,name from t1 #查看表数据 engine = InnoDB 表的存储引擎是InnoDB
mysql> show tables; +------------------+ | Tables_in_xiaoyu | +------------------+ | member | +------------------+ 1 row in set (0.00 sec) mysql> show table(); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘()‘ at line 1 mysql> show create table member\G *************************** 1. row *************************** Table: member Create Table: CREATE TABLE `member` ( `id` int(11) DEFAULT NULL, `name` char(1) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 1 row in set (0.00 sec) mysql> select * from member; +------+------+ | id | name | +------+------+ | 1 | y | +------+------+ 1 row in set (0.00 sec) mysql> select * from member; +------+------+ | id | name | +------+------+ | 1 | y | +------+------+ 1 row in set (0.00 sec) mysql> select id,mane from member; ERROR 1054 (42S22): Unknown column ‘mane‘ in ‘field list‘ mysql> select id,name from member; +------+------+ | id | name | +------+------+ | 1 | y | +------+------+ 1 row in set (0.00 sec)
关于存储引擎:
一种类型表明的是一种存储方式
存储引擎:就是表的类型,不同的类型就会对应不同的处理机制去处理他
事务:就是要么同时成功,要么同时不成功
使用存储引擎
方法1:建表时指定
存储引擎 create table t1(id int) engine = innodb 会出现2个文件 create table t2(id int) engine = myisam 会出现3个文件(速度比上面的快),但是我们还是用innodb存储 create table t3(id int) engine = memory 只有表结构没有表数据,是创建到内存中的 create table t4(id int) engine = blackhole 黑洞,吃数据(数据存进去就没有了,存进去就没有了)
方法2:在配置文件中指定默认的存储引擎
/etc/my.cnf [mysqld] default-storage-engine=INNODB innodb_file_per_table=1
以上是关于库表曾删改查和存储引擎的主要内容,如果未能解决你的问题,请参考以下文章
django制作一个小小的教务系统并且成功部署到腾讯云(实现:增删改查和选课的功能)