如果我的mysql套接字不在/ tmp中,是否可以使用Mysql与SqlAlchemy和Flask? [英] Is it possible to use Mysql with SqlAlchemy and Flask if my mysql socket isn't in /tmp?

查看:133
本文介绍了如果我的mysql套接字不在/ tmp中,是否可以使用Mysql与SqlAlchemy和Flask?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的系统上mysql.sock的位置是 /usr/local/mysql5/mysqld.sock

  thrilllap-2:tmp reuven $ mysqld --print-defaults $ b $ mysqld将会以下列参数启动:
--socket = / usr / local / mysql5 / mysqld.sock - -port = 3306

当我尝试通过sqlalchemy从flask中使用mysql时,我得到:

 在__init__ $ b $文件build / bdist.macosx-10.6-intel / egg / MySQLdb / connections.py b sqlalchemy.exc.OperationalError :( OperationalError)(2002,无法通过套接字连接到本地MySQL服务器/tmp/mysql.sock'(2))无无

mysql程序正确地连接到数据库,就像我系统上的其他mysql客户端一样。

我的my.cnf有一个正确的位置

  [client] 
port = 3306
socket = /usr/local/mysql5/mysqld.sock

[safe_mysqld ]
socket = /usr/local/mysql5/mysqld.sock

[mysqld_safe]
socket = /usr/local/mysql5/mysqld.sock

[mysqld]
socket = /usr/local/mysql5/mysqld.sock
$ b $ port = 3306

基本的SQLAlchemy库有一个选项,您可以在其中指定mysql.sock的位置,但不会通过sqlalchemy / flask库暴露出来

http://packages.python.org/Flask- SQLAlchemy / config.html



我的问题:


  1. Where请问sqlalchemy是否认为/tmp/mysql.sock是正确的位置?
  2. 是否有方法通过Flash-SQLAlchemy连接器更改默认值


解决方案

您将不得不挖掘确切的语法,但对于MySQL我认为他们使用 unix_socket 查询选择。例如:

$ p $ mysql:/// dbname?unix_socket = / opt / mysql / mysql.sock'

应该是SQLAlchemy的连接URI。


The location for mysql.sock on my system is /usr/local/mysql5/mysqld.sock

thrilllap-2:tmp reuven$ mysqld --print-defaults
mysqld would have been started with the following arguments:
--socket=/usr/local/mysql5/mysqld.sock --port=3306 

When I try to use mysql via sqlalchemy from flask, I get:

  File "build/bdist.macosx-10.6-intel/egg/MySQLdb/connections.py", line 187, in __init__
sqlalchemy.exc.OperationalError: (OperationalError) (2002, "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)") None None

The mysql program connects correctly to the database, as does every other mysql client on my system.

My my.cnf has the correct location for the socket

[client]
port            = 3306
socket          = /usr/local/mysql5/mysqld.sock 

[safe_mysqld]
socket      = /usr/local/mysql5/mysqld.sock 

[mysqld_safe]
socket          = /usr/local/mysql5/mysqld.sock 

[mysqld]
socket          = /usr/local/mysql5/mysqld.sock 

port            = 3306

The base "SQLAlchemy" library has an option where you can specify the location of the mysql.sock, but this isn't exposed through the sqlalchemy / flask library

http://packages.python.org/Flask-SQLAlchemy/config.html

My questions:

  1. Where does sqlalchemy get the idea that /tmp/mysql.sock is the correct location?
  2. Is there a way to change the default via the Flash-SQLAlchemy connector

解决方案

You'll have to dig up the exact syntax, but for MySQL I think they use a unix_socket query opt. Something like:

mysql:///dbname?unix_socket=/opt/mysql/mysql.sock'

Should be your connect URI for SQLAlchemy.

这篇关于如果我的mysql套接字不在/ tmp中,是否可以使用Mysql与SqlAlchemy和Flask?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆