美文网首页
MySQL操作

MySQL操作

作者: zoulala | 来源:发表于2017-06-06 13:35 被阅读0次

最近用到Mysql,操作相关的记录如下

系统:Windows     软件相关:Python+mysqldb  

安装MySQL:rj.baidu.com/soft/detail/12585.html

安装Python:略

安装mysqldb:blog.csdn.net/wklken/article/details/7253245


cmd下的操作:

1、登录:>> mysql -u root -p密码

2、展示:   >>show databases;

                    >>show tables;

                    >>describe 列表名;

3、创建库:>>create database 库名;

                  >> create database if not exists 库名;

4、选择库:>>use 库名

5、创建表:>>create table 表名(

id int(1) unsigned not null auto_increment primary key,

data_id int(1),

content text(1000),

time_a  datatime

);

                    >>create table if not exists 表名(同上);

6、检索全部表:SELECT * FROM 表名;

       检索特定行:select *from 表名 where id=2;

       检索特定字段:select id from 表名;

7、更新指定信息:UPDATE 表名 SET content = hello china WHERE id = 2;

8、按关键词检索:SELECT * FROM budejie_db.fristpage WHERE budejie_db.fristpage.id = 2017 OR budejie_db.fristpage.data_id= 2017

OR CAST(budejie_db.fristpage.content AS CHAR CHARACTER SET utf8) COLLATE utf8_general_ci LIKE '%2017%'

OR CAST(budejie_db.fristpage.time AS CHAR CHARACTER SET utf8) COLLATE utf8_general_ci LIKE '%2017%';

其中:2017是关键词,%是(0~n个)通配字符,_是1个通配字符。

8、其他:www.cnblogs.com/bzys/archive/2013/01/20/2869029.html

Python下的操作:

import MySQLdb

db = MySQLdb.connect("localhost","root","560320",port=3306,charset="utf8")

cursor = db.cursor()#cursor()获取操作游标

cursor.execute("create database if not exists budejie_db")#创建数据库

db.select_db('budejie_db')#选中数据库

cursor.execute("select version()")#execute()方法执行sql语句

#data = cursor.fetchone()#fetchone()方法获取操作结果

#print "数据库版本:%s" % data

#cursor.execute("drop table if exists contents")#删除数据表

#创建数据表

sql = "create table if not exists test(" \

"id int(1) unsigned not null auto_increment primary key," \

"data_id int(1)," \

"content text(1000)" \

");"

cursor.execute(sql)

#-------------------测试------------

cursor.execute('insert into test values(NULL,224,"iie");')

cursor.execute('insert into test values(NULL,818,"feiw");')

db.commit()

cursor.close()

db.close()

相关文章

  • 3 MySQL数据库操作

    2 MySQL数据库操作 3.1 MySQL操作数据库 3.2 MySQL操作数据表 3.2.1 MySQL创建数...

  • 基于Linux的MySQL操作实例(软件安装,mysql基本操作

    基于Linux的MySQL操作实例(软件安装,mysql基本操作,mysql数据类型,建表、插入数据操作) 前言 ...

  • Mysql大全

    1.Mac下Homebrew 安装mysql 2.mysql管理 3.mysql数据库操作 4.mysql表操作 ...

  • php操作mysql语句

    mysql语句 php操作mysql语句

  • 搜企网爬虫作业

    作业要求 (1)csv文件数据写入(2)mysql 操作,python mysql操作 这个需要安装mysql以及...

  • python对mysql的操作

    python对mysql的操作 Mysql 常见操作 数据库操作 PS:用户权限相关数据保存在mysql数据库的u...

  • PHP操作mysql

    准备 事实上:PHP本身不能操作数据库(mysql);但是PHP有扩展可以实现操作mysql PHP操作mysql...

  • python作业-20170601

    作业:(1)csv文件数据写入(2)mysql 操作,python mysql操作 这个需要安装mysql以及p...

  • Go操作MySQL

    Go语言操作MySQL MySQL是业界常用的关系型数据库,本文介绍了Go语言如何操作MySQL数据库。 Go操作...

  • MySql笔记

    Mac安装并运行MySql MySql数据库、数据表的操作 MySql数据类型及常见约束 MySql表操作 MyS...

网友评论

      本文标题:MySQL操作

      本文链接:https://www.haomeiwen.com/subject/esvgfxtx.html