[sqlalchemy] SA connect to database remotely

2013-03-13 Thread junepeach
Hello All,

Using sqlalchemy ORM, I have no problem to create a database in mysql locally. 
If I have mysql installed in a different machine (ip address: 10.7.0.127), and 
my tables defined in this machine (10.7.0.121). Now I want to create my 
database tables in mysql database of machine 10.7.0.127. The create engine code 
si:
myengine = create_engine('mysql://root:mypwd@10.7.0.127:3306/%s' % dbname)

when running the python code, and I got error:
Traceback (most recent call last):
  File saintdb_data_model.py, line 55, in module
execute = 
create_engine('mysql://root:mypwd@10.7.0.127:3306').connect().execute
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py, line 
1649, in connect
return self._connection_cls(self, **kwargs)
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py, line 
59, in __init__
self.__connection = connection or engine.raw_connection()
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py, line 
1707, in raw_connection
return self.pool.unique_connection()
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py, line 220, 
in unique_connection
return _ConnectionFairy(self).checkout()
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py, line 425, 
in __init__
rec = self._connection_record = pool._do_get()
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py, line 777, 
in _do_get
con = self._create_connection()
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py, line 225, 
in _create_connection
return _ConnectionRecord(self)
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py, line 318, 
in __init__
self.connection = self.__connect()
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py, line 368, 
in __connect
connection = self.__pool._creator()
  File 
/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/strategies.py, line 
80, in connect
return dialect.connect(*cargs, **cparams)
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/default.py, 
line 279, in connect
return self.dbapi.connect(*cargs, **cparams)
  File /usr/lib/python2.7/dist-packages/MySQLdb/__init__.py, line 81, in 
Connect
return Connection(*args, **kwargs)
  File /usr/lib/python2.7/dist-packages/MySQLdb/connections.py, line 187, in 
__init__
super(Connection, self).__init__(*args, **kwargs2)
sqlalchemy.exc.OperationalError: (OperationalError) (2003, Can't connect to 
MySQL server on '10.7.0.127' (111)) None None

It failed to connect to another computer. What code I can use to connect to 
mysql, oracle? I saw there is a class in sqlalchemy site:
class sqlalchemy.engine.url.URL(drivername, username=None, password=None, 
host=None, port=None, database=None, query=None) 

But I don't know how to make it work? Please help me if you know about it.

Thanks very much for you input!

LYH

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [sqlalchemy] SA connect to database remotely

2013-03-13 Thread Simon King
On Wed, Mar 13, 2013 at 4:00 PM, junepeach juneyh...@gmail.com wrote:
 Hello All,

 Using sqlalchemy ORM, I have no problem to create a database in mysql 
 locally. If I have mysql installed in a different machine (ip address: 
 10.7.0.127), and my tables defined in this machine (10.7.0.121). Now I want 
 to create my database tables in mysql database of machine 10.7.0.127. The 
 create engine code si:
 myengine = create_engine('mysql://root:mypwd@10.7.0.127:3306/%s' % dbname)

 when running the python code, and I got error:
 Traceback (most recent call last):
   File saintdb_data_model.py, line 55, in module
 execute = 
 create_engine('mysql://root:mypwd@10.7.0.127:3306').connect().execute
   File /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py, 
 line 1649, in connect
 return self._connection_cls(self, **kwargs)
   File /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py, 
 line 59, in __init__
 self.__connection = connection or engine.raw_connection()
   File /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py, 
 line 1707, in raw_connection
 return self.pool.unique_connection()
   File /usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py, line 220, 
 in unique_connection
 return _ConnectionFairy(self).checkout()
   File /usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py, line 425, 
 in __init__
 rec = self._connection_record = pool._do_get()
   File /usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py, line 777, 
 in _do_get
 con = self._create_connection()
   File /usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py, line 225, 
 in _create_connection
 return _ConnectionRecord(self)
   File /usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py, line 318, 
 in __init__
 self.connection = self.__connect()
   File /usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py, line 368, 
 in __connect
 connection = self.__pool._creator()
   File 
 /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/strategies.py, 
 line 80, in connect
 return dialect.connect(*cargs, **cparams)
   File /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/default.py, 
 line 279, in connect
 return self.dbapi.connect(*cargs, **cparams)
   File /usr/lib/python2.7/dist-packages/MySQLdb/__init__.py, line 81, in 
 Connect
 return Connection(*args, **kwargs)
   File /usr/lib/python2.7/dist-packages/MySQLdb/connections.py, line 187, 
 in __init__
 super(Connection, self).__init__(*args, **kwargs2)
 sqlalchemy.exc.OperationalError: (OperationalError) (2003, Can't connect to 
 MySQL server on '10.7.0.127' (111)) None None

 It failed to connect to another computer. What code I can use to connect to 
 mysql, oracle? I saw there is a class in sqlalchemy site:
 class sqlalchemy.engine.url.URL(drivername, username=None, password=None, 
 host=None, port=None, database=None, query=None)

 But I don't know how to make it work? Please help me if you know about it.

 Thanks very much for you input!

 LYH


Can you connect using the mysql client directly? What happens when you run this:

  mysql -u root -p -h 10.7.0.127 dbname

Simon

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [sqlalchemy] SA connect to database remotely

2013-03-13 Thread junepeach
I changed the my.conf file and let the bind ip to 0.0.0.0.  However when I 
tested again, same thing also happened by running your code:

sqlalchemy.exc.OperationalError: (OperationalError) (1130, Host 'MYPC-8.local' 
is not allowed to connect to this MySQL server) None None

What I need to change to have the connect right to that computer? Thanks a lot 
for your help!

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [sqlalchemy] SA connect to database remotely

2013-03-13 Thread junepeach
After googling, I found out below code to make it work:
$ mysql -u root -p
Enter password:

mysql use mysql

mysql GRANT ALL ON *.* to root@'192.168.1.4' IDENTIFIED BY 
'your-root-password'; 

mysql FLUSH PRIVILEGES;

Thanks a lot!
LYH

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [sqlalchemy] SA connect to database remotely

2013-03-13 Thread junepeach
OOPs, my mistake. Simon, your command is running fine. But it still doesn't 
work in sqlalchemy ORM code:
Traceback (most recent call last):
  File saintdb_data_model.py, line 55, in module
execute = 
create_engine('mysql://root:mypwd@10.7.0.127:3306').connect().execute
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py, line 
1649, in connect
return self._connection_cls(self, **kwargs)
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py, line 
59, in __init__
self.__connection = connection or engine.raw_connection()
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/base.py, line 
1707, in raw_connection
return self.pool.unique_connection()
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py, line 220, 
in unique_connection
return _ConnectionFairy(self).checkout()
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py, line 425, 
in __init__
rec = self._connection_record = pool._do_get()
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py, line 777, 
in _do_get
con = self._create_connection()
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py, line 225, 
in _create_connection
return _ConnectionRecord(self)
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py, line 318, 
in __init__
self.connection = self.__connect()
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/pool.py, line 368, 
in __connect
connection = self.__pool._creator()
  File 
/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/strategies.py, line 
80, in connect
return dialect.connect(*cargs, **cparams)
  File /usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/default.py, 
line 279, in connect
return self.dbapi.connect(*cargs, **cparams)
  File /usr/lib/python2.7/dist-packages/MySQLdb/__init__.py, line 81, in 
Connect
return Connection(*args, **kwargs)
  File /usr/lib/python2.7/dist-packages/MySQLdb/connections.py, line 187, in 
__init__
super(Connection, self).__init__(*args, **kwargs2)
sqlalchemy.exc.OperationalError: (OperationalError) (1045, Access denied for 
user 'root'@'mypc.local' (using password: YES)) None None

Do you or anyone else here have any idea? Thanks a lot.

LYH 

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [sqlalchemy] SA connect to database remotely

2013-03-13 Thread junepeach
Never mind, It was password typo problem. Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.