问题:

1、centos MySQL启动失败:关闭selinux, vi /etc/selinux/config, 设置SELINUX=disabled,重启电脑;

命令:

停止、启动mysql服务器:/etc/init.d/mysqld {start|stop|status|restart|condrestart|try-restart|reload|force-reload}

DDL(Data Definition Languages)

一、数据库相关

创建数据库:              create database test1;

查看数据库:              show databases;

使用数据库:              use test1;

删除数据库:              drop database test1;

二、表相关

创建表:                    create table student(name varchar(10) primary key, birthday date, weight decimal(10,2), age int(3));

查看数据库的所有表:   show tables;

查看表定义:              desc student;

查看创建表的SQL语句:show create table student \G;  (\G,表示分列显示)

删除表:                    drop table student;

修改表:

1、修改字段类型:   alter table student modify column name varchar(20) first;      //first表示将该列设为第一列,同样适用于其他修改表命令

2、修改字段名称:   alter table student change column age age1 varchar(20);        //同时也要指定字段类型

3、增加表字段:      alter table student add column score int(3) after name;          //after表示插入的列位于name列后,该关键字同样适用于其他修改表命令         4、删除表字段:      alter table student drop column score;

5、修改表名称:      alter table student rename student1;

6、修改表的存储引擎: alter table student engine=innodb;

DML(Data Manipulation Language)

插入记录:                 insert into student (name, birthday) values ('pape', 19880522);

insert into student (name, birthday, weight, age) values ('a', 19880522, 60, 22), ('b', 19880523, 70, 25), ('c', 19890312, 55, 22);                                  //插入多行

更新记录:                 update student set weight=65, age=26 where name='a';

先尝试更新,失败后插入 replace into student (name,birthday) values('pape',19880522)

删除记录:                 delete from student where name='a';

查询记录:

1、查询不重记录:   select distinct age from student;

2、条件查询:         select * from student where age=23 and weight>60;

3、排序和限制:      select * from student order by age desc limit 1,3;

4、聚合:               select name, count(1) from student group by age;

select sum(name), max(age), min(weight) from student;

5、表连接:            select name,age from student,student1 where student.number=student1.number;

6、子查询:            select * from student where number in(select number from student1);

7、记录联合:         select name from student union all select name from student1;  //如果要去重,将union all改为union

DCL(Data Control Language)

授权:                       grant select,insert on test1.* to 'pape'@'localhost' identified by '1234';

收回授权:                 revoke insert on test1.* from 'pape'@'localhost';

可以通过? int; ? show;等进行帮助查询。

MySQL常见问题和命令的更多相关文章

  1. 30.Mysql常见问题和应用技巧

    30.Mysql常见问题和应用技巧30.1 忘记Mysql的root密码30.2 如何处理MyISAM存储引擎的表损坏 30.2.1 方法一:使用myisamchk工具 30.2.2 方法二:使用SQ ...

  2. (转)【面试】【MySQL常见问题总结】【03】

    [常见面试问题总结目录>>>] [面试][MySQL常见问题总结][03] 2016-05-29 22:20 阅读(8244) 评论(2) [面试][MySQL常见问题总结][02] ...

  3. mysql远程连接命令

    mysql远程连接命令   一.MySQL 连接本地数据库,用户名为“root”,密码“123”(注意:“-p”和“123” 之间不能有空格) C:\>mysql -h localhost -u ...

  4. mysql数据库常规命令操作

    1.MySQL数据库导出命令 1.导出整个数据库 mysqldump -u 用户名 -p 数据库名 > 导出的文件名     mysqldump -u wcnc -p smgp_apps_wcn ...

  5. MySQL数据库备份命令

    原文参考:MySQL数据库备份的命令 - 司南 mysqldump -hhostname -uusername -ppassword databasename > backupfile.sql备 ...

  6. CentOS系统操作mysql的常用命令

    MySQL名字的来历MySQL是一个小型关系型数据库管理系统,MySQL被广泛地应用在Internet上的中小型网站中.由于其体积小.速度快.总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为了 ...

  7. 使用Mysql修改密码命令更改root的密码

    使用Mysql修改密码命令更改root的密码. 进入Mysql数据库命令行方式有两种方式: 方式一:在Mysql开始菜单里包含Mysql命令行客户端,只要点击输入root的密码即可进入. 方式二:在D ...

  8. 工作常用的linux/mysql/php/工具命令

    工作常用的linux/mysql/php/工具命令: 1. tar备份目录 tar zcvf ****.tar.gz ****/ tar 备份跳过目录 tar --exclude=test1 3. s ...

  9. Data Base MySQL的常用命令

       MySQL的常用命令 一.下载地址: http://www.mysql.com 二.安装注意: root默认密码:123456 三.常用命令: 1.创建用户并授权: 创建用户,只能本地访问:cr ...

随机推荐

  1. flume学习(四):Flume Interceptors的使用

    转载:http://blog.csdn.net/xiao_jun_0820/article/details/38111305 对于flume拦截器,我的理解是:在app(应用程序日志)和 source ...

  2. swftools使用

    为了支持gif转swf以及pdf转swf.编译swftools过程中遇见几个问题,记录一下. 首先下载swftools:http://www.swftools.org/ 它依赖几个包,这里我使用的版本 ...

  3. 3D数学读书笔记——矩阵基础番外篇之线性变换

    本系列文章由birdlove1987编写.转载请注明出处. 文章链接:http://blog.csdn.net/zhurui_idea/article/details/25102425 前面有一篇文章 ...

  4. C语言可以给字符数组赋值的方法

    分类: C 2012-04-06 10:23 4081人阅读 评论(0) 收藏 举报 语言c 学了这么多年的C语言,突然发现连字符串赋值都出错,真的很伤心. char a[10]; 怎么给这个数组赋值 ...

  5. Android轻量级日志管理框架

    代码地址如下:http://www.demodashi.com/demo/12134.html ViseLog Android 轻量级日志框架,使用森林对象维护不同的日志树进行日志输出,可以是Logc ...

  6. KingdeeK3-修改单据邮件发送的自定义字段

    只需要执行类似下面语句即可: update ICTemplateentry set FVisForBillType = 63,flookupcls=6 where fid ='P01' and fhe ...

  7. js从$scope外部调用$scope内部函数,跨js调用非全局函数

    scope内部函数定义 //定位 $scope.LocateByPoint = function (x,y) { if(!x || !y) { window.alert("GPS坐标不存在, ...

  8. matlab-非线性方程求根函数及函数曲线绘制

    Matlab中提供了很多求解非线性方程(y=f(x))的函数,刚開始使用,真的很困惑.全部.这里依据matlab的help文档对这些函数做一些小小的总结 fsolve函数 用来求解非线性方程组:F(x ...

  9. PHP接收和发送XML数据(json也通用)

    一.接收xml数据, 使用php://input,代码如下: <?php $xmldata=file_get_contents("php://input"); $data=s ...

  10. MySQL四-2:完整性约束

    阅读目录 一 介绍 二 not null与default 三 unique 四 primary key 五 auto_increment 六 foreign key 七 作业 一 介绍 约束条件与数据 ...