最近在学习mysql数据库,一些记录总结

本文介绍了在Windows XP系统上安装MySQL 5.5.30的过程及注意事项,并提供了使用MySQL Workbench进行基本操作的示例,包括数据库创建、表定义、数据插入等。此外,还展示了如何使用Java连接MySQL数据库。

在window  xp上使用mysql-installer-community-5.5.30.1.msi装了相应版本的mysql。可从http://dev.mysql.com/获取相应的安装包。本来想装5.6的版本,发现官网声明5.6版本不支持window xp,就没装。装的过程发现需要.net framework相关东西,直接在360的软件管理中安装了.net framework,安全方便。

安装完毕后,在

在开始-程序-mysql中启动mysql workbench,按照官网的介绍尝试了下面的命令,

using mysql work bench:
1,query operation:
select VERSION(),CURRENT_DATE;
select SIN(PI()/4),(4+1)*5;
select version();
select now();
select user();
2, Use the show statement to find out what databases currently exist on the server:
show databases;
3,create database:
create database bestree;
4,create a table:
show tables;
create table pet(name varchar(20),owner varchar(20),
species varchar(20),sex char(1),birth date,death date);
5,show tables;
describe pet;
6,
load data local infile 'E:\pet.txt' into table pet lines terminated by '\r\n';
7,
insert into pet values('bestree','best','fa','f','1988-3-4',NULL);
as you can see 
String and date values are specified as quoted strings here.and 
you can insert NULL directly to represent a missing value
8,select
select * from pet where name='bestree';
select * from pet;
select * from pet where birth>='1988-2-28';
select * from pet where (species='cat' and sex='m')or (species='dog' and sex='f');
9, select particular column
select name,birth from pet;
10,order by
select name,birth from pet order by birth;
感觉还不错。

后来想通过eclipse写java代码访问下数据库,于是百度了下,下面代码参考了百度的结果

public class Test {
	public static void main(String[] args) {
		String driver = "com.mysql.jdbc.Driver";
		try {
			Class.forName(driver);
			// 连续数据库
			Connection conn = DriverManager
					.getConnection("jdbc:mysql://localhost:3306/bestree",
							"bestree", "");

			if (!conn.isClosed()) {
				System.out.println("Succeeded connecting to the Database!");
			}
			// statement用来执行SQL语句
			Statement statement = conn.createStatement();
			// 要执行的SQL语句
			String sql = "select * from pet";
			ResultSet rs = statement.executeQuery(sql);
			while (rs.next()) {
				String name = rs.getString("name");
				System.out.println(name);
			}
			rs.close();
			conn.close();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {

		}

	}
}

运行上面代码之前,需要将mysql-connector-java-5.1.23-bin.jar包放置到classpath目录。

 有尝试了下面的命令

1,查看目前选中的数据库:
select database();
2,查看当前数据库下的表:
show tables;
3,查看每个表的结构:
desc pet;
4,查看某个表的索引:
show index from pet;












评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值