asp技术网站开发案例,wordpress 发邮件插件,成都网站建设服务公司,wordpress nginx 500错误一、mysql简单介绍说到数据库#xff0c;我们大多想到的是关系型数据库#xff0c;比如mysql、oracle、sqlserver等等#xff0c;这些数据库软件在windows上安装都非常的方便#xff0c;在Linux上如果要安装数据库#xff0c;咱不得不首先推荐的是mysql数据库了#xff0…一、mysql简单介绍说到数据库我们大多想到的是关系型数据库比如mysql、oracle、sqlserver等等这些数据库软件在windows上安装都非常的方便在Linux上如果要安装数据库咱不得不首先推荐的是mysql数据库了而且Mysql数据库的第一个版本就是发行在Linux系统上的。MySQL是一个关系型数据库管理系统由瑞典MySQL AB公司开发目前属于Oracle公司。MySQL是一种关联数据库管理系统关联数据库将数据保存在不同的表中而不是将所有数据放在一个大仓库内这样就增加了速度并提高了灵活性。MySQL的SQL语言是用于访问数据库的最常用标准化语言。MySQL软件采用了双授权政策(本词条“授权政策”)它分为社区版和商业版由于其体积小、速度快、总体拥有成本低尤其是开放源码这一特点一般中小型网站的开发都选择MySQL作为网站数据库。由于其社区版的性能卓越搭配PHP和Apache可组成良好的开发环境二、安装msql1、centos6.4编译安装mysql参考地址http://www.centoscn.com/CentosServer/sql/2014/0316/2584.html2、windows安装msyql官网下载地址http://dev.mysql.com/downloads/mysql/三、mysql简单操作可用过客户端远程操作mysqlNavicat for MySql工具1、启动数据库链接数据库2、显示数据库默认数据库mysql - 用户权限相关数据test - 用于用户测试数据information_schema - MySQL本身架构相关数据2、使用数据库3、用户授权用户管理创建用户create user 用户名IP地址 identified by 密码;删除用户drop user 用户名IP地址;修改用户rename user 用户名IP地址; to 新用户名IP地址;;修改密码set password for 用户名IP地址 Password(新密码)PS用户权限相关数据保存在mysql数据库的user表中所以也可以直接对其进行操作(不建议)授权管理show grants for 用户IP地址 -- 查看权限grant 权限 on 数据库.表 to 用户IP地址 -- 授权revoke 权限 on 数据库.表 from 用户IP地址 -- 取消权限all privileges 除grant外的所有权限select 仅查权限select,insert 查和插入权限...usage 无访问权限alter 使用alter tablealter routine 使用alter procedure和drop procedurecreate 使用create tablecreate routine 使用create procedurecreate temporary tables 使用create temporary tablescreate user 使用create user、drop user、rename user和revoke all privilegescreate view 使用create viewdelete 使用deletedrop 使用drop tableexecute 使用call和存储过程file 使用select into outfile 和 load data infilegrant option 使用grant 和 revokeindex 使用indexinsert 使用insertlock tables 使用lock tableprocess 使用show full processlistselect 使用selectshow databases 使用show databasesshow view 使用show viewupdate 使用updatereload 使用flushshutdown 使用mysqladmin shutdown(关闭MySQL)super 使用change master、kill、logs、purge、master和setglobal。还允许mysqladmin调试登陆replication client 服务器位置的访问replication slave 由复制从属使用权限对于目标数据库以及内部其他数据库名.*数据库中的所有数据库名.表 指定数据库中的某张表数据库名.存储过程 指定数据库中的存储过程*.* 所有数据库数据库用户名IP地址 用户只能在改IP下才能访问用户名192.168.1.% 用户只能在改IP段下才能访问(通配符%表示任意)用户名% 用户可以再任意IP下访问(默认IP地址为%)对于用户和IP四、表操作1、在库中创建表use test #选择test库create table 表名( #创建表列名 类型 是否可以为空列名 类型 是否可以为空)是否可空null表示空非字符串not null - 不可空null - 可空默认值创建列时可以指定默认值当插入数据时如果未主动设置则自动添加默认值create table tb1(nid int not null defalut 2,num int not null)自增如果为某列设置自增列插入数据时无需设置此列默认将自增(表中只能有一个自增列)create table tb1(nid int not null auto_increment primary key,num int null)或create table tb1(nid int not null auto_increment,num int null,index(nid))注意1、对于自增列必须是索引(含主键)。2、对于自增可以设置步长和起始值show session variables like auto_inc%;set session auto_increment_increment2;set session auto_increment_offset10;shwo global variables like auto_inc%;set global auto_increment_increment2;set global auto_increment_offset10;主键一种特殊的唯一索引不允许有空值如果主键使用单个列则它的值必须唯一如果是多列则其组合必须唯一。create table tb1(nid int not null auto_increment primary key,num int null)或create table tb1(nid int not null,num int not null,primary key(nid,num))外键一个特殊的索引只能是指定内容creat table color(nid int not null primary key,name char(16) not null)create table fruit(nid int not null primary key,smt char(32) null ,color_id int not null,constraint fk_cc foreign key (color_id) references color(nid))2、数据表操作#基于Navicat for MySql工具实现操作show tables; #查询库中有哪些表create table lcj(id int not null auto_increment PRIMARY KEY, #PRIMARY KEY主键IP 自增name char(30) not null,sex char(4) not null,age tinyint unsigned not null,tel char(13) null default -); #电话默认为-SELECT * from lcj; #查询表#插入数据insert into lcj VALUES(0001,xiaoluo,男,18,13520617734)#同时插入多条数据insert into lcj VALUES(0004,xiaoluo,男,18,13520617734),(0002,qq,man,18,13212345432),(0003,ww,gril,19,13567890987);#更新数据;将ID为3的姓名改为lcjUPDATE lcj set name lcj WHERE id 3;#查看字典条数据SELECT name from lcj where id 2;#查看所有数据SELECT * from lcj#删除数据DELETE from lcj WHERE id 4;清空表delete from 表名truncate table 表名修改表添加列alter table 表名 add 列名 类型删除列alter table 表名 drop column 列名修改列alter table 表名 modify column 列名 类型; -- 类型alter table 表名 change 原列名 新列名 类型; -- 列名类型添加主键alter table 表名 add primary key(列名);删除主键alter table 表名 drop primary key;alter table 表名 modify 列名 int, drop primary key;添加外键alter table 从表 add constraint 外键名称(形如FK_从表_主表) foreign key 从表(外键字段) references 主表(主键字段);删除外键alter table 表名 drop foreign key 外键名称修改默认值ALTER TABLE testalter_tbl ALTER i SET DEFAULT 1000;删除默认值ALTER TABLE testalter_tbl ALTER i DROP DEFAULT;基本数据类型MySQL的数据类型大致分为数值、时间和字符串参考地址http://www.runoob.com/mysql/mysql-data-types.htmlmysql其他操作1、条件select * from 表 where id 1 and name ! alex and num 12;select * from 表 where id between 5 and 16;select * from 表 where id in (11,22,33)select * from 表 where id not in (11,22,33)select * from 表 where id in (select nid from 表)2、通配符select * from 表 where name like ale% - ale开头的所有(多个字符串)select * from 表 where name like ale_ - ale开头的所有(一个字符)3、限制select * from 表 limit 5; - 前5行select * from 表 limit 4,5; - 从第4行开始的5行select * from 表 limit 5 offset 4 - 从第4行开始的5行4、排序select * from 表 order by 列 asc - 根据 “列” 从小到大排列select * from 表 order by 列 desc - 根据 “列” 从大到小排列select * from 表 order by 列1 desc,列2 asc - 根据 “列1” 从大到小排列如果相同则按列2从小到大排序5、分组select num from 表 group by numselect num,nid from 表 group by num,nidselect num,nid from 表 where nid 10 group by num,nid order nid descselect num,nid,count(*),sum(score),max(score),min(score) from 表 group by num,nidselect num from 表 group by num having max(id) 10特别的group by 必须在where之后order by之前6、连表无对应关系则不显示select A.num, A.name, B.namefrom A,BWhere A.nid B.nid无对应关系则不显示select A.num, A.name, B.namefrom A inner join Bon A.nid B.nidA表所有显示如果B中无对应关系则值为nullselect A.num, A.name, B.namefrom A left join Bon A.nid B.nidB表所有显示如果B中无对应关系则值为nullselect A.num, A.name, B.namefrom A right join Bon A.nid B.nid7、组合组合自动处理重合select nicknamefrom Aunionselect namefrom B组合不处理重合select nicknamefrom Aunion allselect namefrom B五、基于Pycharm中pymysql模块实现mysql操作1、Pycharm安装pymysql模块2、简单使用pymysql某块1)插入数据通过pymysql向远程数据库同时插入多条数据并打印插入数据条数#!/usr/bin/env python# -*- coding:utf-8 -*-# Author:lcjimport pymysql#连接数据库conn pymysql.connect(host192.168.1.152,port 3306,user root,passwd123123,dbtest) #db库名#创建游标cur conn.cursor()#插入一条数据# reCount cur.excute(insert into lcj(name,age) values(%s,%s),(ff,18))#向test库中的lcj表插入# ret cur.executemany(insert into lcj(name,tel)values(%s,%s), [(kk,13212344321),(kw,13245678906)])#同时向数据库lcj表中插入多条数据ret cur.executemany(insert into lcj values(%s,%s,%s,%s,%s), [(41,xiaoluo41,man,24,13212344332),(42,xiaoluo42,gril,21,13245678948),(43,xiaoluo43,gril,22,13245678949),(44,xiaoluo44,main,24,13543245648)])#提交conn.commit()#关闭指针对象cur.close()#关闭连接对象conn.close()#打印结果print(ret)2)查询数据在Pycharm控制台输出lcj表中数据# !/usr/bin/env python# -*- coding:utf-8 -*-# Author:lcjimport pymysql#连接数据库conn pymysql.connect(host192.168.1.152,port 3306,user root,passwd123123,dbtest) #db库名#创建游标cur conn.cursor()#查询lcj表中存在的数据cur.execute(select * from lcj)#fetchall:获取lcj表中所有的数据ret1 cur.fetchall()print(ret1)print(----------------------)#获取lcj表中前三行数据ret2 cur.fetchmany(3)print(ret2)print(------------------------------)#获取lcj表中第一行数据ret3 cur.fetchone()print(ret3)#同时向数据库lcj表中插入多条数据# ret cur.executemany(insert into lcj values(%s,%s,%s,%s,%s), [(41,xiaoluo41,man,24,13212344332),# (42,xiaoluo42,gril,21,13245678948),# (43,xiaoluo43,gril,22,13245678949),# (44,xiaoluo44,main,24,13543245648)])#提交conn.commit()#关闭指针对象cur.close()#关闭连接对象conn.close()注在fetch数据时按照顺序进行可以使用cursor.scroll(num,mode)来移动游标位置如cursor.scroll(1,moderelative) # 相对当前位置移动【1表示向下移动一行-1表示向上移动一行】cursor.scroll(2,modeabsolute) # 相对绝对位置移动 【1表示向上移动一行-1表示向下移动一行】3)删除数据# !/usr/bin/env python# -*- coding:utf-8 -*-# Author:lcjimport pymysql#连接数据库conn pymysql.connect(host192.168.1.152,port 3306,user root,passwd123123,dbtest) #db库名#创建游标cur conn.cursor()#删除cj表中数据cur.execute(delete * from lcj)#提交conn.commit()#关闭指针对象cur.close()#关闭连接对象conn.close()4)修改表中的数据# !/usr/bin/env python# -*- coding:utf-8 -*-# Author:lcjimport pymysql#连接数据库conn pymysql.connect(host192.168.1.152,port 3306,user root,passwd123123,dbtest) #db库名#创建游标cur conn.cursor()#将lcj表中id3的name 修改为lcjjcur.execute(UPDATE lcj set name lcjj WHERE id 3) #逼表中所有的操作都可以再此进行操作#提交conn.commit()#关闭指针对象cur.close()#关闭连接对象conn.close()5)fetch数据类型关于默认获取的数据是元祖类型如果想要或者字典类型的数据即# !/usr/bin/env python# -*- coding:utf-8 -*-# Author:lcjimport pymysql#连接数据库conn pymysql.connect(host192.168.1.152,port 3306,user root,passwd123123,dbtest) #db库名#设置游标类型默认游标类型为元祖形式#将游标类型设置为字典形式cur conn.cursor(cursorpymysql.cursors.DictCursor)cur.execute(select * from lcj) #逼表中所有的操作都可以再此进行操作#将lcj表中所有数据以字典形式输出ret cur.fetchall()print(ret) #[{age: 18, tel: 13520617734, name: xiaoluo, id: 1, sex: ?},#提交conn.commit()#关闭指针对象cur.close()#关闭连接对象conn.close()继续完善中