MySQL數(shù)據(jù)庫的基本知識大全
以下的文章主要介紹的是MySQL數(shù)據(jù)庫的基本知識,其中包括對MySQL數(shù)據(jù)庫的創(chuàng)建,以及對一些相關(guān)的數(shù)據(jù)類型描述,其中還涉及到表的創(chuàng)建,以下就是文章的詳細(xì)內(nèi)容描述,望你會有所收獲。
MySQL數(shù)據(jù)庫安裝 ***改變字符集UTF8
創(chuàng)建數(shù)據(jù)庫
- create database mydata;
- use mydata;
數(shù)據(jù)類型 int double char varchar datetime longtext
創(chuàng)建表 create table dept
- (
- deptno int primary key,
- dname varchar(14),
- loc varchar(13)
- );
- create table emp
- (
- empno int primary key,
- ename varchar(10),
- job varchar(15),
- mgr int,
- hiredate datetime,
- sal double,
- deptno int,
- foreign key (deptno) references dept(deptno)
- );
MySQL數(shù)據(jù)庫執(zhí)行腳本文件.sql \. 文件路徑 或 source 文件路徑
?
sql文件中 -- 注釋
MySQL管理軟件 MySQL administrator,toad for MySQL
查看數(shù)據(jù)庫 show databases;
查看表 show tables;
查看表結(jié)構(gòu) desc dept;
插入數(shù)據(jù)
- intsert into dept values(1,'a','a');
- commit;
分頁 select * from dept order by deptno desc limit 3,2; (從第三條往后數(shù)兩條)
自增 create table article
- (
- id int primary key auto_increment,
- title vachar(255)
- );
- insert into article values(null,'a');
- insert into article(title) values('c');
日期處理
獲取當(dāng)前日期 select now();
轉(zhuǎn)化字符串 select date_format(now(),'%Y-%m-%d %H:%i:%s');
- jdbc連接MySQL
- Connection conn=null;
- Statement stmt=null;
- ResultSet rs=null;
- try{
- Class.forName("com.MySQL.jdbc.Driver").newInstance();
- conn=DriverManager.getConnection("jdbc:MySQL://localhost/test? user=root&password=root");
- stmt=conn.createStatement();
- rs = stamt.executeQuery(sql);
- }
- catch(Exception e){}
- finally{
- try{
- if(rs!=null){rs.close; rs=null;}
- if(stat!=null){stat.close; stat=null;}
- if(conn!=null){conn.close; conn=null;}
- }
- catch(SQLException e){
- e.printStackTrace();
- }
- }
以上的相關(guān)內(nèi)容就是對MySQL數(shù)據(jù)庫知識的介紹,望你能有所收獲。
【編輯推薦】