create database MyDB;
grant all privileges on MyDB to MyName@'%' identified by "pwd"
数据库:MyDB
用户名:MyName
密码:pwd
执行下列SQL:
/创建数据库/
create database student
on primary
(
name='stu',
filename='D:\stumdf',
size=10,
maxsize=100,
filegrowth=10
),
(
name='stu1',
filename='D:\stu1ndf',
size=10,
maxsize=100,
filegrowth=10
),
filegroup fgroup1
(
name='stu2',
filename='D:\stu2ndf',
size=10,
maxsize=100,
filegrowth=10
)
log on
(
name='stu_log',
filename='D:\stu_logldf',
size=10,
maxsize=100,
filegrowth=10
)
/在Student数据库中创建表Stu/
use Student
go
Create Table Stu
(
Stu_id int primary key,
Stu_Name varchar(20) unique ,
Stu_Sex char(2) check(Stu_Sex in('男','女')),
Stu_Age int check(Stu_Age>0 and Stu_Age<200),
Stu_Date datetime default getdate()
)
下面是一个简单的连接MySQL数据库,并 *** 作数据库表的例子:
import javasql;
public class TestMysql {
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
//加载驱动
ClassforName("commysqljdbcDriver");
//创建连接
conn = DriverManager
getConnection("jdbc:mysql://localhost/bbsuser=用户名&password=密码");
stmt = conncreateStatement();
rs = stmtexecuteQuery("select from user");
while (rsnext()) {
String user = rsgetString(1);
String password = rsgetString(2);
Systemoutprintln("用户名:" + user + "," +" 密码:" + password );
}
} catch (ClassNotFoundException ex) {
exprintStackTrace();
} catch (SQLException ex) {
exprintStackTrace();
} finally {
try {
if (rs != null) {
rsclose();
rs = null;
}
if (stmt != null) {
stmtclose();
stmt = null;
}
if (conn != null) {
connclose();
conn = null;
}
} catch (SQLException e) {
eprintStackTrace();
}
}
}
}
当然前提是要把MySQL的连接驱动JAR文件添加到工程里
以上就是关于如何新建一个MYSQL数据库全部的内容,包括:如何新建一个MYSQL数据库、C# 动态闯将数据库和表(sqlserver,mysql)、java语言如何动态循环创建mysql数据库基本表,可以实现吗等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)