查询mysql增删库的⽇志_MySQL数据库篇之库的增删改查主要内容:
⼀、系统数据库介绍
⼆、创建数据库
三、数据库增删改查
四、MySQL添加注释
1  系统数据库介绍
1、初识sql语句
有了mysql这个数据库软件,就可以将程序员从对数据的管理中解脱出来,专注于对程序逻辑的编写
mysql服务端软件即mysqld帮我们管理好⽂件夹以及⽂件,前提是作为使⽤者的我们,需要下载mysql的客户端,
或者其他模块来连接到mysqld,然后使⽤mysql软件规定的语法格式去提交⾃⼰命令,实现对⽂件夹或⽂件的管理。
该语法即sql(Structured Query Language 即结构化查询语⾔)
SQL语⾔主要⽤于存取数据、查询数据、更新数据和管理关系数据库系统,SQL语⾔由IBM开发。SQL语⾔分为3种类型:1、DDL语句 数据库定义语⾔: 数据库、表、视图、索引、存储过程,例如CREATE DROP ALTER2、DML语句 数据库操纵语⾔: 插⼊数据INSERT、删除数据DELETE、更新数据UPDATE、查询数据SELECT3、DCL语句 数据库控制语⾔: 例如控制⽤户的访问权限GRANT、REVOKE
2、MySQL数据库登录后,查看数据库的初始数据库(show databases; ),⼀般会有以下⼏个库⽂件:
information_schema: 虚拟库,不占⽤磁盘空间,存储的是数据库启动后的⼀些参数,如⽤户表信息、列信息、权限信息、字符信息等
performance_schema: MySQL5.5开始新增⼀个数据库:主要⽤于收集数据库服务器性能参数,记录处理查询请求时发⽣的各种事件、锁等现象
mysql: 授权库,主要存储系统⽤户的权限信息
test: MySQL数据库系统⾃动创建的测试数据库
2  创建数据库
1、语法
create database 数据库 charset utf8;
2、数据库命名规则
可以由字母、数字、下划线、@、#、$
区分⼤⼩写
唯⼀性
不能使⽤关键字如 create select
不能单独使⽤数字
最长128位
3  数据库相关操作
SQL语句:
操作⽂件夹(库)
增 create database db1 charset utf8;
查 show create database db1;
查看所有数据库(show databases;)
改数据库:alter database db1 charset gbk;
删数据库:drop database db1;
操作⽂件
切换⽂件夹:use db1;
增 :create table t1(id int,name char);
查:
查看当前所在⽂件夹:select database();
查看当前库中所有表 :show tables;
查看当前表:show create t3\G 或者:desc t1;(更直观)
改:
alter table t1 modify name char(6);
alter table t1 change name Name char(7);
删:
drop table t1;
pycharm智能提示
操作⽂件内容(记录):
增:insert t1(id,name) value(1,'cc'),(2,'cc2'),(3,'cc3');
查:select id,namefromdb1.t1;
mysql查看所有存储过程select* fromdb1.t1;
改:update db1.t1 set name='CC';(表中内容全改)
update db1.t1 set name='hyt' where id=2;
删:deletefromt1;
deletefrom t1 where id=2;
4    MySQL添加注释
在MySQL数据库中, 字段或列的注释是⽤属性comment来添加。
创建新表的脚本中, 可在字段定义脚本中添加comment属性来添加注释。
怎么做网页广告1、在新建表的时候添加注释
mysql>create table test(-> id int primary key comment '添加注释测试',-> name varchar(20)->); Query OK, 0 rows affected (0.39 sec)
查看添加的注释的表信息,可使⽤语句 “show full columns from test;”
mysql> show full columns fromtest;+-------+-------------+-----------------+------+-----+---------+-------+---------------------------------+--------------------+
| Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment |
+-------+-------------+-----------------+------+-----+---------+-------+---------------------------------+--------------------+
| id | int(11) | NULL | NO | PRI | NULL | | select,insert,update,references | 添加注释测试 |
| name | varchar(20) | utf8_general_ci | YES | | NULL | | select,insert,update,references | |
+-------+-------------+-----------------+------+-----+---------+-------+---------------------------------+--------------------+
2 rows in set (0.00 sec)
2、为建好的表添加或修改注释
mysql> alter table test comment'这是测试表';
Query OK, 0 rows affected (0.16sec)
Records: 0 Duplicates: 0 Warnings: 0
查看表的的注释(两种⽅法)
# ⽅法⼀:在⽣成的SQL语句中看 (show create table 表名\G;),实例如下:
mysql> show create table test\G; #\G 表⽰格式化显⽰
*************************** 1. row ***************************Table: test
Create Table: CREATE TABLE `test` (
`id` int(11) NOT NULL COMMENT '添加注释测试',
`name` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='这是测试表'
1 row in set (0.00sec)
ERROR:
No query specified
View Code
# ⽅法⼆:在元数据的表⾥⾯看(复杂⼀点)
过程:
use information_schema;
select* from tables where table_schema='数据库名' and table_name='表名' \G
实例:
mysql> select * from tables where table_schema='db1' and table_name='test'\G;*************************** 1. row
***************************TABLE_CATALOG:defTABLE_SCHEMA: db1
TABLE_NAME: test
TABLE_TYPE: BASE TABLE
ENGINE: InnoDB
VERSION:10ROW_FORMAT: Compact
TABLE_ROWS: 0
AVG_ROW_LENGTH: 0
DATA_LENGTH:16384MAX_DATA_LENGTH: 0
INDEX_LENGTH: 0
DATA_FREE: 0
AUTO_INCREMENT: NULL
CREATE_TIME:2018-06-02 12:15:31UPDATE_TIME: NULL
rhel7CHECK_TIME: NULL
ajax请求success时出现异常TABLE_COLLATION: gbk_chinese_ci
CHECKSUM: NULL
CREATE_OPTIONS:
TABLE_COMMENT: 这是测试表1 row in set (0.00sec)
ERROR:
黄安仪辱华事件
No query specified
View Code
3、为建好的表⾥的字段添加或修改注释,并查看效果
mysql> alter table test change column id id int not null default 0 comment '测试表id';
Query OK, 0 rows affected (0.17sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show full columns fromtest;+-------+-------------+----------------+------+-----+---------+-------+---------------------------------+-------------+
| Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment |
+-------+-------------+----------------+------+-----+---------+-------+---------------------------------+-------------+
| id | int(11) | NULL | NO | PRI | 0 | | select,insert,update,references | 测试表id |
| name | varchar(20) | gbk_chinese_ci | YES | | NULL | | select,insert,update,references | |
+-------+-------------+----------------+------+-----+---------+-------+---------------------------------+-------------+
2 rows in set (0.00sec)
mysql> alter table test change column id id int not null default 1 comment '修改后的测试表id';
Query OK, 0 rows affected (0.13sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show full columns fromtest;+-------+-------------+----------------+------+-----+---------+-------+---------------------------------+-------------------------+
| Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment |
+-------+-------------+----------------+------+-----+---------+-------+---------------------------------+-------------------------+
| id | int(11) | NULL | NO | PRI | 1 | | select,insert,update,references | 修改后的测试表id |
| name | varchar(20) | gbk_chinese_ci | YES | | NULL | | select,insert,update,references | |
+-------+-------------+----------------+------+-----+---------+-------+---------------------------------+-------------------------+
2 rows in set (0.02 sec)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。