mysql的基本语句(一)
来源:互联网 发布:假面骑士数据排行 编辑:程序博客网 时间:2024/06/06 05:24
一 登录到服务器
1、 mysql –hlocalhost –uroot –p口令
2、 直接利用开始菜单!开始----程序---mysql5.0
二 命令的简单使用
下面的操作一般就是使用标准SQL命令:也就是说你在SQL SERVER里面怎么用,这里就怎么用,但是有的命令也不是完全一样的。有一点点细微的差别!下面咱们就把这个命令简单的过一遍:
my sql 命令的使用:以分号或\g结束,\c取消一行命令,\h帮助
显示数据库
show databases;建数据库
create database [if not exists] 数据库名;建数据表create table [if not exists] 表名 (字段名1 类型。。。。。。。。) create table student (编号 int auto_increment primary key, 姓名 varchar(10));显示数据表:show tables;删除库drop database [if exists] 库名; 删除表:
drop table [if exists] 表名;显示表结构desc 表名增长一个字段alter table 表名 add 字段名 类型删除一个字段alter table 表名 drop 字段名修改一个字段的属性alter table 表名modify 字段 新属性增加一个主键 alter table 表名 add primary key(字段名) 删除一个主键alter table 表名 drop primary key(字段名)
三 有关于数据库的操作
show databases; //显示所有数据库
use userpro_db; //使用哪个数据库
show tables; //显示数据库下的表
四 表的操作
创建表:Create TABLE mytable (name VARCHAR(20), sex CHAR(1),birth DATE, birthaddr VARCHAR(20));
选择列:select * from table where 范围
插入数据:insert into table(field1,field2) values(value1,value2)
删除数据:delete from table where 范围
更新数据:update table set field=value1 where 范围
模糊查找:select * from table where field like '%value%' ---like的语法很精妙,查资料!
数据排序:select * from table order by field1,field2 [desc]
数据总数:select count as totalcount from table
数据求和:select sum(field) as sumvalue from table
数据平均:select avg(field) as avgvalue from table
最大数据:select max(field) as maxvalue from table
最小数据:select min(field) as minvalue from table
五 用户的操作
新建用户
(1)、创建用户(会使用到mysql数据库)
mysql> insert into mysql.user(Host,User,Password)values('localhost','nine',password('mirchd'));
(2)、刷新系统权限表
mysql> flush privileges;
(3)、修改用户密码
mysql> update mysql.user setpassword=password('123') where User='nine' andHost='localhost';
(4)、授权nine用户拥有tree数据库的所有权限
mysql> grant all privileges on tree.* tonine@localhost identified by '123';
删除用户
mysql> delete from user where User='nine' andHost='localhost';
最好每一步都刷新系统权限表
- mysql的基本语句(一)
- Mysql的基本语句(一)
- mysql 总结一(基本语句)
- MySQL的基本语句
- mysql的基本语句
- mysql基本语句操作(一)--一对一的实现
- MySQL数据库中SQL语句的基本使用(一)
- mysql基本sql语句总结(一)
- MySql的基本语句操作
- 基本的MYSQL语句大全
- mysql的基本查询语句
- MYSQL常用的基本语句
- 一些基本的mysql语句
- mysql基本的语法/语句
- mysql基本的语法/语句
- mysql的基本操作语句
- MySQL的一些基本语句
- MySQL中SELECT语句的基本语法
- 正则表达式邮箱匹配详解
- DataGridView之为每行前面添加序号
- linux文件系统(三)——进程与VFS的关系
- C学习之路_7
- JAVA基础之集合数组详解
- mysql的基本语句(一)
- Trie树详解及其应用
- [20140311]CSDN不能”原生“支持LaTex公式吗?
- delphi三层架构
- Sublime 2 配置编译环境[Windows]
- 窗体间传值得几种方法
- 成功没有捷径
- linux文件系统(四)——软连接与硬连接
- 【NOI2012】美食节