大众世界 world of demotic + 社区新动力

 找回密码
 注册会员
搜索
查看: 5115|回复: 3

[PHP] mysql 合集

[复制链接]
发表于 2014-7-25 16:09:12 | 显示全部楼层 |阅读模式
dd

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
回复

使用道具 举报

 楼主| 发表于 2014-7-25 16:11:05 | 显示全部楼层
用sql脚本建立Mysql数据库及表

建立一个名为DBName的数据库,并建立图书表、用户表、订单表、用户订货表

drop database if exists DBName;

create database DBName;

use DBName;


create table t_Book
(
bookId int unsigned primary key not null auto_increment,
name varchar(50) not null,
author varchar(20) not null,
isbn char(20) not null,
edition varchar(10) not null,
press varchar(20) not null,
publicData datetime not null,
catagory varchar(50) not null,
price decimal not null,
description varchar(500) not null,
pic varchar(100) not null,
sold int unsigned not null,
sum int unsigned not null,
upShelfDate datetime not null,
downShelfDate datetime not null
);


create table t_User
(
userId int unsigned primary key not null auto_increment,  
name varchar(20) not null,
pass varchar(20) not null,
type varchar(10) not null,
address varchar(100) not null,
postCode varchar(6) not null,
phoneNumber varchar(11) not null,
email varchar(30) not null
);


create table t_Order
(
orderId int unsigned primary key not null auto_increment,
totalPrice decimal not null,
status varchar(20) not null,
orderTime datetime not null,
payWay varchar(20) not null,
userId int unsigned not null ,
bookId int unsigned not null ,
orderNumber int unsigned not null,
foreign key(userId) references t_User(userId) on update cascade,
foreign key(bookId) references t_Book(bookId) on update cascade
);


create table t_UserOrder
(
userId int unsigned not null ,
bookId int unsigned not null,
orderId int unsigned not null,
primary key(userId,bookId,orderId)
);

将以上代码保存为*.sql文件放入预定目录

在终端中输入“mysql -u root -p”
输入密码:
进入Mysql数据库
输入“source 文件路径\*.sql;”
执行*.sql文件,数据库及表即建立完成。
回复

使用道具 举报

 楼主| 发表于 2014-7-25 16:11:50 | 显示全部楼层
最近使用mysql数据库的时候遇到了多种数字的类型,主要有int,bigint,smallint和tinyint。其中比较迷惑的是int和smallint的差别。


今天就在网上仔细找了找,找到如下内容,留档做个总结:
使用整数数据的精确数字数据类型。

bigint
从 -2^63 (-9223372036854775808) 到 2^63-1 (9223372036854775807) 的整型数据(所有数字)。存储大小为 8 个字节。
P.S. bigint已经有长度了,在mysql建表中的length,只是用于显示的位数

int
从 -2^31 (-2,147,483,648) 到 2^31 – 1 (2,147,483,647) 的整型数据(所有数字)。存储大小为 4 个字节。int 的 SQL-92 同义字为 integer。

smallint
从 -2^15 (-32,768) 到 2^15 – 1 (32,767) 的整型数据。存储大小为 2 个字节。

tinyint
从 0 到 255 的整型数据。存储大小为 1 字节。

注释

在支持整数值的地方支持 bigint 数据类型。但是,bigint 用于某些特殊的情况,当整数值超过 int 数据类型支持的范围时,就可以采用 bigint。在 SQL Server 中,int 数据类型是主要的整数数据类型。
在数据类型优先次序表中,bigint 位于 smallmoney 和 int 之间。
只有当参数表达式是 bigint 数据类型时,函数才返回 bigint。SQL Server 不会自动将其它整数数据类型(tinyint、smallint 和 int)提升为 bigint。
int(M) 在 integer 数据类型中,M 表示最大显示宽度。在 int(M) 中,M 的值跟 int(M) 所占多少存储空间并无任何关系。和数字位数也无关系 int(3)、int(4)、int(8) 在磁盘上都是占用 4 btyes 的存储空间。
回复

使用道具 举报

 楼主| 发表于 2016-3-24 13:36:49 | 显示全部楼层
win10安装mysql绿色版 ,
安装mysql时出现 mysql Install/Remove of the Service Denied! 错误的解决办法

用cmd在mysql的bin目录下面执行: mysqld --install 命令,出现错误: mysql Install/Remove of the Service Denied!



解决方法:以管理员身份运行CMD,再运行安装

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Archiver|手机版|小黑屋|Wod Inc. ( 蜀ICP备20000008号-8

GMT+8, 2024-5-11 00:07 , Processed in 0.129669 second(s), 40 queries .

Powered by Discuz! X3.5

Copyright © 2001-2023 Tencent Cloud.

快速回复 返回顶部 返回列表