笔记
1.查看所有数据库
Show databases;
2.打开指定的库
Use +库
3.查看当前库的所有表
Select tables from 库名
4.查看其它库的所有表
Select *from 库名
5.创建表
Create table 表名(
列名 列类型,
列名 列类型,)
6.查看表结构
Desc 表;
7.查看服务器版本
Select version();
未登录时:mysql –version
Mysql –V
8.插入数据到表中
Insert into 表名(列名,列名)values(数据,’数据’);
9.改变数据库数据
Update 表名 set 列名= where 列名=
10.删除数据
Delete from 表名 where 列名=;
11.条件查询
Select ..... from ...where...
条件:<=小于
Between .... and ...或 >= and <=
!= 和 <> 是不等于
Is null 为空(is not null 不为空)
And 和 or 同时先执行and
In(...,.....) 是.....or .....
Ont in(....,....)
like‘ % ....%’ 找出有....的 \可以将特殊字符转为普通字符
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/world";
String user = "root";
String pwd ="";
Connectio connection = DriverManager.getConnection(url,user,pwd);
if(connection == null){
System.out.println("连接失败");
}else {
System.out.println("连接成功");
Statement statement =connection.createStatement();
String sql = "update stuinfo set id=5 where name='kao'";
if(statement.executeUpdate(sql)>=1){
System.out.println("输入成功");
}else {
System.out.println("失败");
}
connection.close();

浙公网安备 33010602011771号