python更新資料庫
㈠ 如何通過python程序知道mssql資料庫是否更新了
通過python程序知道mssql資料庫是否更新,要實現這樣一個功能,使用python連接sqlserver資料庫,並返回當前資料庫時間。
import os,pymssql
server="192.186.1.26\nwork"
user="np"
password="np.123"
conn=pymssql.connect(server,user,password,database="master")
cursor=conn.cursor()
cursor.execute("""select getdate()""")
row=cursor.fetchone()
while row:
print("sqlserver version:%s"%(row[0]))
row=cursor.fetchone()
conn.close()
㈡ 如何用python更新oracle資料庫
用python更新oracle資料庫:
1. 要想使Python可以操作Oracle資料庫,首先需要安裝cx_Oracle包,可以通過下面的地址來獲取安裝包:cx-oracle.sourceforge.net/
2. 另外還需要oracle的一些類庫,此時需要在運行python的機器上安裝Oracle Instant Client軟體包,可以通過下面地址獲得technetwork/database/features/instant-client/index-097480.html
找到符合自己平台的包,然後安裝,這里我使用的是rpm包,所以使用以下命令安裝
$ sudo rpm -ivh oracle-instantclient11.2-basic-11.2.0.3.0-1.i386.rpm
裝完畢後還需要設置一下環境變數,如下
$ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/lib/oracle/11.2/client/lib
然後寫update語句對表進行更新:
import cx_Oracle //導入鏈接oracle的庫
conn = cx_Oracle.connect('fkong/[email protected]/orcl') //建立與orcl的連接
cursor = conn.cursor () //打開游標
cursor.execute ("update test set COL1='u' where ID=1") //執行更新
conn.commit() //提交結果
cursor.close (); //關閉游標
conn.close ();//關閉連接
㈢ python資料庫更新操作求助
importMySQLdb
#主機名
HOST='127.0.0.1'
#用戶名
USER="root"
#密碼
PASSWD="123456"
#資料庫名
DB="db_name"
#打開資料庫連接
db=MySQLdb.connect(HOST,USER,PASSWD,DB)
#獲取操作游標
cursor=db.cursor()
if__name__=='__main__':
ifcursor:
command_a="updatetables_onesetstatus=5wherestatus=0"
#使用execute方法執行SQL語句
cursor.execute(command_a)
#提交到資料庫執行
db.commit()
command2="selectfieldfromtables_onewhereid=12"
ret2=cursor.execute(command2)
#獲取所有記錄列表
ret2=cursor.fetchall()
foriteminret2:
command3="insertintotables_two(name)values(%s);"%(item[0])
fin=cursor.execute(command3)
db.commit()
#關閉資料庫連接
db.close()
㈣ python連接MYSQL資料庫,調用update語句後無法更新數據,求大神解決
sql_Update="updateomssm.t_securitylogsetDATETIME=0whereSN=%s;"
curA.execute(sql_Update,[Str_Sn,])
conn.commit()#在update之後加個commit試試
㈤ update更新資料庫 python
這樣試試
sql = "update staff_everymonth_overtimes set Jan=%s,Feb=%s where id=1" %('Jan','Feb')
㈥ 如何用python更新mysql資料庫數據
mysql> show databases; // 查看當前所有的資料庫
+--------------------+
| Database |
+--------------------+
| information_schema |
| csvt |
| csvt04 |
| mysql |
| performance_schema |
| test |
+--------------------+
6 rows in set (0.18 sec)
mysql> use test; //作用與test資料庫
Database changed
mysql> show tables; //查看test庫下面的表
Empty set (0.00 sec)
//創建user表,name 和password 兩個欄位
mysql> CREATE TABLE user (name VARCHAR(20),password VARCHAR(20)); Query OK, 0 rows affected (0.27 sec)
//向user表內插入若干條數據
mysql> insert into user values('Tom','1321');
Query OK, 1 row affected (0.05 sec)
mysql> insert into user values('Alen','7875');
Query OK, 1 row affected (0.08 sec)
mysql> insert into user values('Jack','7455');
Query OK, 1 row affected (0.04 sec)
//查看user表的數據
mysql> select * from user;
+------+----------+
| name | password |
+------+----------+
| Tom | 1321 |
| Alen | 7875 |
| Jack | 7455 |
+------+----------+
3 rows in set (0.01 sec)
//刪除name 等於Jack的數據
mysql> delete from user where name = 'Jack';
Query OK, 1 rows affected (0.06 sec)
//修改name等於Alen 的password 為 1111
mysql> update user set password='1111' where name = 'Alen';
Query OK, 1 row affected (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 0
//查看錶內容
mysql> select * from user;
+--------+----------+
| name | password |
+--------+----------+
| Tom | 1321 |
| Alen | 1111 |
+--------+----------+
3 rows in set (0.00 sec)
㈦ python update動態數據到mysql
sql="UPDATE USER SET dataaddress=dataadd, datauser=datauser, datapw=datapw, databa=datapw WHERE username='zhaop'"
這樣試試
㈧ python 更新資料庫語句問題
你後面的port的欄位類型是文本或字元串型的吧。在等號後面是不是需要加上雙引號或單引號叱?
㈨ Python的mysql資料庫的更新如何實現
conn本來 就已經被你定義成了 函數, conn.ping()當然不存在了。而且你要的資料庫連接c,還被手動關回閉了答。我覺得有兩點 1. 按照你這個腳本的情況,你用一次,就新建一個資料庫連接問題應該不大。 2. 要保持使用一個連接的話。把c作全局變數 c=MyS...