mysql
来源:互联网 发布:js除法取整 编辑:程序博客网 时间:2024/06/06 20:11
mysql应用:
1,登录:
配置环境变量:
我的电脑->属性->高级->环境变量
选择PATH,在其后面添加: 你的mysql文件夹路径/bin (如:D:\Program Files\MySQL\MySQL Server 5.0\bin )
PATH=.......;D:\Program Files\MySQL\MySQL Server 5.0\bin (注意为追加,不是覆盖)
dos>mysql -uroot -p123
2,修改密码:
dos>mysqladmin -uroot -p123 password新密码
3,登录成功标记:
mysql>
4,创建数据库:
mysql>create database 数据库名称
5,查看当前用户具有的数据库
mysql>show databases
6,打开数据库
mysql>use 数据库名称
7,数据类型:
整形:int(n) -- int(3) 范围 0-999 可以越界
decimal(n) -- n位整数,不能越界
字符串:char
varchar
中文最好用nvarchar
小数:decimal(n,m)
日期:datetime ---
timestamp --- 自动具有默认值为系统时间
8,自动增长列
auto_increment ,必须是主键
9,建表示例:
mysql> create table student
-> (
-> studentid int(4) auto_increment primary key,
-> studentname varchar(30) not null,
-> time1 datetime,
-> time2 timestamp
-> );
Query OK, 0 rows affected (0.03 sec)
10,增删改同 oracle
11,sql脚本:
脚本内容:
drop database if exists db4;
create database db4;
use db4;
create table product
(
productid int(4) auto_increment primary key,
productname varchar(30) not null,
price decimal(7,2),
indate timestamp
);
insert into product(productid,productname,price) values(1001,'apple',1.8);
insert into product(productname,属性price) values('iphone',4500);
insert into product(productname,price) values('ipad',3000);
select * from product;
12.查询数据库中的用户
select user();
select user(),now();
13,查看数据库的版本号
select verstion ();
14,指定查询的数据记录
select * from pet imit 3;
select * from pet limit 1,3;# limit从0开始算,查询3条记录
15,,查询记录的总数
select count(*) from pet;
select count(id) from pet;
16 以通配符表示的条件查询
select name from pet where name owner='G%'; --表示以G开头
select name from pet where name owner='%y'; --表示以y结尾
select name from pet where name owner='%e%';--表示包含有e的
select name from pet where name owner='_ _ _ _ _ _';--表示匹配字符查询,' - '代表一个字符
select name from pet where death is null; --表示查询为空值的
用正则表达式查询
select name from pet where name regexp '^B';
select name from pet where name regexp 'y$';
select name from pet where name regexp '^.....$';
select name from pet where name regexp '^.{5}$';
select name from pet where name regexp '.e.';
17,复制表中的数据到另外一个表中
select table event2 as select * from event;
create table pet3 as select * from pet where 1=0; --仅仅拷贝表的结构,
18,字段别名
select distinct p.name,p.birth from event as e,pet as p where e.type='litter' and e.name=p.name;
- Mysql
- MySql
- MYSQL
- MySQL
- mysql
- mysql
- mysql
- mysql
- Mysql
- Mysql
- mysql
- MySQL
- mysql
- Mysql
- mysql
- mysql
- mysql
- mySQL
- Android防火墙+流量统计代码
- IE与火狐兼容 JavaScript 获得选中的下拉框文本
- SELECT INTO 和 INSERT INTO SELECT 两种表复制语句
- 2010网络管理员试题
- 遍历当前窗体控件为textbox时的值
- mysql
- 有关linux下执行脚本
- Boost 线程同步机制
- U-BOOT LCD分析
- wait 和 waitpid 差别
- java 调用ffmpeg 进行图片格式转换
- 桌面定制
- ASP开发中存储过程应用全接触
- selenium+testNG-自动化测试环境的搭建