天天看点

前端工程师的mysql笔记

背景

最近常参与后台php项目,虽说刚毕业时自学过一阵子php和mysql,不过长时间没用也忘差不多了,于是把mysql再温习一遍,前端同学也可以一起学习下!

mysql安装以及操作

安装

brew install mysql           

启动

$: mysql.server start           

关闭

$:mysql.server stop           

连接

$:mysql -u root -p           

检查mysql进程

ps -ef | grep mysqld           

问题

重启mysql提示MySQL server PID file could not be found!

1. ps -ef|grep mysqld 
2. kill -9 进程号 
           

DML&DDL

数据操作语言DML

  • select
  • update
  • delete
  • insert into

数据定义语言DDL

  • crate database
  • alter database
  • create table
  • alter table
  • drop table
  • crate index
  • drop index

SQL

基础操作

创建数据库

mysql> create database test           

查看数据库

mysql>  show databases;           

使用test数据库

mysql>  use test           

查看表

mysql>  show tables;           

一,基础教程

创建表

mysql> create table person (id int(4) not null primary key auto_increment,lastname varchar(20) not null,firstname varchar(20),age int(4),sex int(4) not null,address varchar(20));           

插入数据

mysql> insert into person  value (null,'hao','jery',13,1,'beijing');           

删除一行数据

mysql> delete from person where id  = 4;           

查询去重

mysql> select distinct lastname from person;           

where

mysql> select * from person where address = 'beijing';           

and

mysql> select * from person where age>13 and age<26;           

or

mysql> select * from person where age<20 or age >25;           

order by

mysql> select * from person order by age;
mysql> select lastname,age from person order by age;
mysql> select lastname,age from person order by age asc; //顺序显示
mysql> select lastname,age from person order by age desc;//逆向显示           

mysql> update person set lastname='zhuxiaoxiao' where lastname='du';
 mysql> update person set lastname='update',age=27 where id = 12;           

mysql> delete from person where lastname ='zhixiang';           

一览

前端工程师的mysql笔记