MySQL操作数据库基本操作
2015-04-03 10:07
162 查看
MySQL操作数据库基本操作
mysql -uroot -p 进入mysqlmysql -uhdw -p
进入hdw用户mysql
net stop wampmysqld 停止服务
net start wampmysqld 启动服务
mysqladmin -uroot -p shutdown 关闭mysqladmin
\c 取消所有命令 Esc 取消本行命令
(1)数据库操作
create database think character set utf8 创建数据库think,设置编码为utf8
show databases
查看数据库
use think 选择数据库think
drop database think 删除数据库think
grant all on wish.* to "hdw" @"localhost" identified by "hdw" 只允许hdw用户操作数据库wish,密码是hdw
C://mysqldump -uroot -p houdunwang > d:/houdunwang.sql 将数据导出d:/houdunwang.sql
C://mysql -uroot -p houdunwang < d:/houdunwang.sql 将数据d:/houdunwang.sql
导入
mysql>source d:/houdunwang.sql
将数据d:/houdunwang.sql 导入
(2)对数据库中表的操作
create table hd_wish(id int unsigned not null primary key auto_increment, username varchar(20) not null default '',content
varchar(255) not null default '',time int(10) not null default 0) engine myisam charset utf8;
创建表hd_wish(primary key 定义这个字段为主键,auto_increment 定义这个字段为自动增长,引擎为myisam,字符集为utf8)
insert into hd_user set username='admin' 向表hd_user中插入数据(非标准版)
insert into hd_user(username) values('admin',) 向表hd_user中插入数据(标准版)
show tables 查看表名
desc hd_wish 查看表hd_wish结构
drop table hd_wish 删除表hd_wish
select *from hd_wish 查看表hd_wish中的所有数据
delete from hd_wish 将表hd_wish中的记录清空
delect from hd_wish where username="admin" 可用 WHERE 子句来选择所要删除的记录
select count(*) from hd_wish 统计表hd_wish中有多少条记录
select *from stu where sname like "李%"
模糊匹配
select if(sex "男生","女生") as stusex,sname from stu as取别名(stusex)
select concat("姓名:",sname,"性别:",sex,"QQ",qq) as stuinfo from stu
字符串与字段进行连接
alter table stu add birday date
增加表stu字段
update stu set birday="1990/2/23" where id=1
修改表stu数据
select *from stu order by id desc limit 0,1 从第零个开始取1个
select distinct year(birday) as "出生年份" from stu distinct去掉重复的部分,year(birday)只得到年份
相关文章推荐
- 数据库基本操作小摘(代码由mysql-essential-5.1.50-win32测试通过)
- MySQL学习笔记2:数据库的基本操作(创建删除查看)
- Mysql 数据库基本操作总结
- 数据库基本操作Mysql与Oracle
- Linux 下的MySQL安装 以及数据库的基本操作
- mysql 数据库基本操作
- 数据库MySQL的基本操作命令
- mysql 基本操作----数据库的操作
- MySQL 5.6学习笔记(数据库基本操作,查看和修改表的存储引擎)
- MySQL基础-数据库基本操作
- oracle mysql sqlserver 查看当前所有数据库及数据库基本操作命令
- MySql的基本用法(2)_常见的数据库操作
- 数据库基本操作与mysql错误号
- oracle mysql sqlserver 查看当前所有数据库及数据库基本操作命令
- 数据库基本操作小摘(代码由mysql-essential-5.1.50-win32测试通过)
- MySQL学习笔记2:数据库的基本操作
- mysql笔记二:基本数据库、表查询操作
- mysql笔记三:基本数据库、表创建更新操作
- DF学Mysql(一)——数据库基本操作
- MYSQL入门学习之八:数据库及表的基本操作