DB数据库,Database
DBMS数据库管理系统,DatabaMemanagmentSystem
SQL结构化查询语言,structure Query Language

开启服务
net start mysql80

登录
mysql -u root -p

显示数据库

show databases;

使用数据库
use mysql;

显示数据库表
show tables;
show tables from mysql;

显示数据库
select database();

desc stuinfo;

创建数据库
create database test;

创建数据库表

create table customer(id int,name varchar(20),password varchar(20),email varchar(30));

删除某列

alter table customer drop id;

插入一条数据
insert into stuinfo(id,name) values(1,'John');

查询
select * from stuinfo;

修改
update stuinfo set name='jack' where id=1;

删除字段

alter table songinfo drop id;

删除值
delete from stuinfo where id=1;

插入新字段在...之后(增加字段)

alter table songinfo add id int primary key auto_increment after score;

插入新字段最前面

alter table songinfo add id int primary key auto_increment first;

插入布尔型

alter table post add essence bit;

重置id

alter table news auto_increment=1;

修改字段名

alter table groupcategory change title grouptitle varchar(10);

修改字段类型

alter table t_hp_new modify column thumb blob;

升序/倒序查询

select * from user order by id asc;

select * from user order by id desc;

显示版本
select version();

修改密码

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

保存图片为二进制数据流

创建表:create table pic_bin(id INT PRIMARY KEY AUTO_INCREMENT,filename VARCHAR(100),data MEDIUMBLOB);

java存储代码

try {
conn = JdbcUtil.connection();
String sql1="insert into pic_bin(filename,data) values(?,?)";
ps = conn.prepareStatement(sql1);
ps.setObject(1,"a.jpg"); InputStream in=new FileInputStream("C:\\Users\\Administrator\\Desktop\\test.jpg");
ps.setObject(2,in); ps.execute();
}catch (Exception e){
e.printStackTrace();
}finally {

java读取代码

try {
conn = JdbcUtil.connection();
String sql1="select filename,data from pic_bin where id=?";
ps = conn.prepareStatement(sql1);
ps.setObject(1,"1"); rs=ps.executeQuery(); if(rs.next()){
String filename=rs.getString("filename"); InputStream in=rs.getBinaryStream("data"); OutputStream out=new FileOutputStream("f:\\"+filename);
out.write(in.readAllBytes()); out.close();
}

最新文章

  1. [备忘]没有为扩展名“.cshtml”注册的生成提供程序
  2. Matlab Map
  3. springmvc使用RSA算法加密表单
  4. 【转】http-equiv="X-UA-Compatible" 设置IE浏览器兼容模式详解
  5. (转)现代C++函数式编程
  6. 如何隐藏storyboard中的top bar
  7. Oracle Lock 概述
  8. js定时显示广告代码
  9. 自制单片机之十一……模数转换IC ADC0809
  10. python 文本编辑基础记录
  11. 最简单的MFC
  12. PTVS在Visual Studio中的安装
  13. Linux基础教程
  14. [P4基础]p4app的Docker镜像仓使用详解
  15. 学JAVA的第十九天,抽象类注意事项
  16. 使用Maven的assembly插件实现自定义打包
  17. 痞子衡嵌入式:ARM Cortex-M文件那些事(3)- 工程文件(.ewp)
  18. n 个骰子的点数
  19. Teradata超长数据会截断
  20. web页面简单布局的修改,测试中的应用

热门文章

  1. HiBench成长笔记——(2) CentOS部署安装HiBench
  2. DB2的简单操作
  3. 【LeetCode】排列硬币
  4. windows清理命令
  5. validate表单验证-单独验证
  6. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-star-empty
  7. scan port
  8. HihoCoder第七周:完全背包问题
  9. 国产超低功耗蓝牙5.0 PHY6202替换NRF51822
  10. MongoDB 常用查询语法