常用的mysql语句
来源:互联网 发布:张北阿里云招聘 编辑:程序博客网 时间:2024/04/29 19:38
MySQL的连接
(1)连接到本机的MySQL
进入cmd输入MySQL -u root -p,回车键后会提示输入密码(注:u后面可以没有空格,但是密码必须有空格,否则无法进入)
(2)连接到远程主机的MySQL
进入cmd,键入命令MySQL IP地址 -u 用户名 -p 密码
修改密码
命令格式:MySQLadmin -u 用户名 -p 旧密码 password 新密码
创建数据库
命令格式: create database 数据库名
显示数据库
命令格式 show databases(注意后面的s不能省略)
删除数据库
命令格式:drop database 数据库名
连接数据库
命令格式:use 数据库名
创建数据库表
命令格式:create table(表名) ([字段名1 类型1],......,[类型n 类型n])(如果只有一个字段名不需要中括号)
例如:use abc(abc为数据库名) (首先连接数据库在进行标的创建)
create table Userinfo(Userinfo为表名) (name varchar(20), pass varchar(20))(注:如果需要设置主键并且是自增长语句为 字段名+primary key auto_increment)
删除数据表
命令格式:drop table 表名
例如:drop table abc(表名)
表插入数据
命令格式:insert into 表名 (字段名1,.......,字段名n) values (值1,........,值n)(注:在插入值时,如果值为varchar放在引号里面,一条语句只能插入一次)
查询表中的数据
select 字段(可为多个) from 表名 where 表达式
例如:查询所有 select * from userinfo(表名)
删除表中的数据
命令格式:delete from 表名 where 表达式
例如:delete from userinfo where id=1 (删除userinfo表中的id为1的所有值)
修改表中的数据
命令格式:update 表名 set 字段=修改的值(可以为多个) where 表达式
例如:update userinfo set name="ss" where id=2
增加字段
命令格式:alter table 表名 add 字段
例如:alter table userinfo add sex varchar(20) default ‘ 男’(在userinfo表中添加字段sex,sex的默认值为男,注意男要用单引号)
添加索引
命令格式:alter table 表名 add index 索引名 (字段名1,.............,字段名2)
例如:alter table userinfo add index emp_name(name)
加主关键字的索引
命令格式:alter table 表名 add primary key (字段名);
例如:alter table userinfo add primary key(id)
删除索引名
命令格式:alter table 表名 drop index 索引名
例如:alert table userinfo drop index emp_name
修改字段名及类型
命令格式:alter table 表名 change 原字段名 new 新字段名 新的类型
例如:alter table userinfo change name new username char;
删除字段
alter table 表名 drop 字段名
例如:alter table userinfo drop name
修改表名
命令格式:rename table 原表名 to 新表名
例如:rename table userinfo to tb_user
0 0
- 常用的mysql语句
- MySql常用的语句
- 常用的MYsql语句
- MYSQL的常用语句
- 常用的MySQL语句
- 常用的mysql语句
- 常用的mysql语句
- mysql的常用语句
- MySQL的常用语句
- 常用的mysql语句
- 常用的MySQL语句
- 常用的MYSQL语句
- 常用的mysql语句
- mysql常用的语句
- 常用的mysql 语句
- mysql 常用的语句
- 常用的mysql语句
- MySQL常用的语句记录
- Error:Cannot build Artifact :war exploded because it is included into a circular depency
- Linux vi命令大全
- UVA 10003 Cutting Sticks 区间DP
- Java Web项目导出excel表,地址栏中文正常,但是文件下载报404中文文件名乱码
- hdoj 1052 Tian Ji -- The Horse Racing
- 常用的mysql语句
- 【HDOJ 2444】The Accomodation of Students
- java 获取当前系统时间 时间大小比较
- 王者归来-上
- hdu 5317 RGCDQ(素数筛选法+前缀和)
- 跟我上“云”端(四)使用eclipselink构建企业级多租户应用
- 记一次我在华为和中兴的面试经历
- JAVA学习路线图---(JAVA1234)
- 随机验证码的生成