zoukankan      html  css  js  c++  java
  • Python—>Mysql—>Dbvisualizer

     MySQLdb:

    https://pypi.python.org/pypi/MySQL-python/1.2.4

     import MySQLdb

    1.Download Connector/Python:mysql-connector-python-2.1.3-py2.7-win32

    Mysql:mysql-installer-community-5.5.48.0

    Python:python-2.7.10

    2.安装好Python,Mysql

    Connector/Python:  http://dev.mysql.com/doc/connector-python/en/connector-python-installation.html

    Python3不再支持mysqldb,

    取而代之的是:import pymysql

    Python MySQL 官方包:mysql-connector-python

    3.测试代码

    Mysql:查看所有用户  select * from mysql.user;

    show databases ;    ----------查看全部数据库 

    use test; --使用数据库

    # -*- coding: utf8 -*-
    
    import mysql.connector
    
    conn=mysql.connector.connect(
                        host='127.0.0.1',
                        port=3306,
                        user='root',
                        passwd='1qaz@WSX',
                        db='test',
                        )  
    
    cursor = conn.cursor()        
    cursor.execute ("SELECT VERSION()")
    row = cursor.fetchone ()
    
    print "server version:", row[0] 
    
    cursor.close()  
    conn.close()

    4.管理数据库

    DbVisualizer 8.0.8管理

    CREATE TABLE 表名 (字段名 VARCHAR(20), 字段名 CHAR(1));

    create table pet(

    name varchar(20), #名字

    owner varchar(20),#主人

    species varchar(20), #种类       

    sex char(1),  #性别      

    birth date, #出生日期       

    death date,#死亡日期)

    show tables;

    select * from tb;

    要建立外键关系,首先要保证用来建立外键关系的列具有唯一性,即具有 UNIQUE 约束

    通常是某表的主键作为另外一个表的外键

    mysql版本和驱动版本不匹配

    An error occurred while executing the database request for:
    MySQL
    5.5.47-log
    MySQL-AB JDBC Driver
    mysql-connector-java-5.1.16 ( Revision: ${bzr.revision-id} )

    Short message:
    An error occurred while performing the operation:
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1

    The command that caused the problem:
    ALTER TABLE testdjango.student ADD CONSTRAINT student_fk1 FOREIGN KEY (ScoreID) REFERENCES testdjango.pet ()

    Long Message:
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1

    Details:
       Type: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException
       Error Code: 1064
       SQL State: 42000

    System Information:
    Product: DbVisualizer Personal 8.0.8
    Build: #1745 (2012/02/14 10:52)
    Java VM: Java HotSpot(TM) Client VM
    Java Version: 1.6.0_20
    Java Vendor: Sun Microsystems Inc.
    OS Name: Windows 7
    OS Arch: x86
    OS Version: 6.1

    下载更新驱动:

    mysql-connector-java-5.1.38.zip

    最后更新到dbvis jar包到相应的目录下就行

    image

    DbVisualizer-8.0.8jdbcmysql

    失败原因:

    image

    http://www.cnblogs.com/edisonfeng/archive/2014/06/05/3766243.html 

    Msql终端添加:

    alter table student add constraint score_student_fk1 foreign key (ScoreID)  references score(ScoreID)

    alter table student add constraint score_student_fk1 foreign key (ScoreID) references score(ScoreID)
    三年有成,问苍茫~
  • 相关阅读:
    动态封杀与解封IP
    潜谈IT从业人员在传统IT和互联网之间的择业问题(下)-互联网公司
    潜谈IT从业人员在传统IT和互联网之间的择业问题(上)-传统乙方形公司
    博主2000年真实遇鬼记-仅作记录以供后人参考
    异步请求引发的Chrome死锁
    jboss规则引擎KIE Drools 6.3.0 Final 教程(3)
    jboss规则引擎KIE Drools 6.3.0 Final 教程(2)
    jboss规则引擎KIE Drools 6.3.0 Final 教程(1)
    商品搜索引擎---推荐系统设计
    大道理很多人都懂,只是坚持不下去(浅谈坚持)
  • 原文地址:https://www.cnblogs.com/lynclynn/p/5232047.html
Copyright © 2011-2022 走看看