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.connectorconn=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包到相應的目錄下就行
DbVisualizer-8.0.8\jdbc\mysql
失敗原因:
?
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)轉載于:https://www.cnblogs.com/lynclynn/p/5232047.html
總結
以上是生活随笔為你收集整理的Python—Mysql—Dbvisualizer的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 百度智能云之语音技术(自动播报语音)
- 下一篇: 路由器常规功能使用方法及设置心得 路由器