Linux基本操作及数据库查询

来源:互联网 发布:sql语句 修改 编辑:程序博客网 时间:2024/05/18 21:09

Linux

命令

文件、目录操作

    touch     rm  -rf    mv     cp目录:    mkdir    rm -rf    mv      cp  -r

编辑文件:

    vim         命令模式            hjkl            yy  复制            nyy  复制多行            dd    删除            ndd   删除多行            r => 你要替换的内容            gg  第一行            G  最后一行            :/查找的内容                    n  下一个                    N  上一个        插入模式            i  o        编辑模式            Esc =>  :ls ls -lls -all ls -h 

cd 切换目录

cd 回家cd ~ 回家cd -

挂载: mount /dev/sr0 /mnt/cdrom/

下载: wget URL

安装二进制包: yum -y install 包名

     rpm -ivh    包全名

源码包安装:

    具体看源码包手册        ./configure --prefix=/usr/loca/nginx        make        make install

ifconfig

ifconfig eth0 192.168.17.66

setup

netstat -tlunp 查看端口

几个比较重要的文件

//自启/etc/rc.local//存用户信息/etc/passwd//存Linux用户的密码

/etc/shadow

LAMP相关配置文件

Apache配置文件

/usr/local/apache2/etc/httpd.conf

MySQL配置文件

/etc/my.cnf

PHP配置文件
/usr/local/php/etc/php.ini

Nginx配置文件

/usr/local/nginx/conf/nginx.conf

软件管理

//启动apache/usr/local/apache2/bin/apachectl start/restart/stop//启动mysql/usr/local/mysql/bin/mysqld_safe --user=mysql &//停止mysql/usr/local/mysql/bin/mysqladmin -uroot -p shutdown 

MySQL常用操作: 增(insert)/删(delete)/改(update)查(select)

一般网站都是读多写(增删改)少。

mysql查询

分类:

  1. 单表查询 2、多表联查

    select 字段列表 from 表名 where … order by … group by … having limit ..

多表查询

  1. user表是一个常用的表(登录、注册),所以不能将一些不常用的字段(age/sex)放到user中。

多表联查分类:

  1. 利用where来进行一个多表联查

  2. 连接

    a. 内连接(inner join)    //就是等同于where    select * from user  inner join user_detail on user.id = user_detail.uidb. 左连接    会查询出左表的所有的数据,不管右表是否有与之对应的数据。    //写到left join 左边的表就是左表,会查询出坐表所有数据    select * from user left join user_detail  on user.id=user_detail.uid;c. 右连接(right join)    会查询出右表的所有数据,不管左表是否有与之对应的数据    select * from user_detail right join user on user.id = user_detail.uid

    查询出所有用户的所有数据

其他注意问题

  1. 视图、触发器、存储过程这个在互联网项目中是不使用的。因为这三个东西效率低。

    互联网项目: 一般指的是对外的网站/app

    OA系统(上班打卡、出差申请、报销): 非互联网项目

  2. 子查询效率低,一般不使用

    //这个就是所谓子查询
    select * from user where id in (select uid from user_detail);

重点

  1. 连接(左连接、右连接、内连接)

  2. 分组、聚合函数

    聚合函数:

    count() 统计行数max()min()avg()sum() 求总和group_concat() 得到组内的所有成员
原创粉丝点击