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