上图来源于TIOBE,打开此页面,即可看到最新的图片。如上图所示,Python在语言排名中,是位于第一位的。那么达梦数据库支持Python么?其实大家都知道,肯定支持。那么我们改如何配置才能连接数到达梦数据库呢?
位于安装数据库软件安装目录
/home/dmdba/dmdbms/drivers/python/ --默认安装路径 django-comment-migrate 'DM8 - dmPython.pdf' dmDjango dmPython dmSQLAlchemy --pdf文件为手册
通过pdf手册,可以对用法有更一步的了解。
dmdba用户操作: cd dmPython/ python3 setup.py install running install error: can't create or remove files in install directory The following error occurred while trying to add or remove files in the installation directory: [Errno 13] Permission denied: '/usr/local/lib64/python3.7' The installation directory you specified (via --install-dir, --prefix, or the distutils default setting) was: /usr/local/lib64/python3.7/site-packages/ This directory does not currently exist. Please create it and try again, or choose a different installation directory (using the -d or --install-dir option). 碰到以上报错,只需要做对应的赋权即可。我们以/usr/local为例 mkdir -pv /usr/local/lib64/python3.7/site-packages/ ---root执行 chmod 777 /usr/local/lib64/python3.7/site-packages/ --根据实际情况授权 root执行 再次执行 python3 setup.py install 即可。 ....... ...... Installed /usr/local/lib64/python3.7/site-packages/dmPython-2.5.8-py3.7-linux-x86_64.egg Processing dependencies for dmPython==2.5.8 Finished processing dependencies for dmPython==2.5.8 出现以上输出,即安装完成。
python3
Python 3.7.9 (default, Mar 18 2024, 13:55:37)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dmPython
>>> dmPython.version
'2.5.8'
>>>
如上则正确安装dmPython模块
cat dmtest.py
import dmPython
conn=dmPython.connect(user='SYSDBA',password='Dameng',server='localhost',port=5236)
cursor=conn.cursor()
cursor.execute('select employee_id from dmhr.employee limit 10 ')
res=cursor.fetchall()
print ( res )
cursor.close()
conn.close()
python3 dmtest.py
[(1001,), (1002,), (1003,), (1004,), (1005,), (1100,), (1101,), (1102,), (1103,), (1104,)]
代码验证输出结果正常
以上所有均为数据库安装用户dmdba执行。遗留个小小的问题:如果代码执行换成root的话,还会执行成功么?欢迎大家讨论
以上内容为个人对达梦学习的初步认知,受限于视角与经验,不足之处恳请指正。
文章
阅读量
获赞
