Domanda

Trying to get Emacs' sql-mysql to work with an Amazon EC2.

(Technically I think this should be in superuser, but there are 10 times more Emacs questions here, so I am guessing there are more Emacs users here.)

I have successfully used ssh ec2-user@<elastic ip address>, and from that command line, mysql -u root -p to get a successful MySQL prompt and show databases;. But I can't reliably get Emacs' sql-mysql to work (I think it worked once).

So in my ignorance, I have permuted the variables about. That is, the command sql-mysql prompts for User:, Password:, Database: and Server:.

For User: and Password:, I use same as I do from ssh ec2-user@<elastic ip address>.

For Database:, I have tried leaving it blank, but I think the time it worked I used mysql.

For Server:, I have tried a bunch, including

localhost
localhost@<elastic ip address>
ec2-user@<elastic ip address>
<elastic ip address>

One of the handful of error messages I get is

Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

I have tried fiddling with other Emacs variables, such as default-directory and sql-port, but to no noticeable effect.


Additional notes:

I have tried using command line mysql with more options, to try to mimic the same variables, ala

mysql -u root -p -h localhost@ec2-<elastic ip address>.us-west-2.compute.amazonaws.com --port=3306

but I get unknown server host.

I have seen mention of using command echo $db_host, but I get nothing. This may be that I have only just initialized all of this.

I have also gone into AWS console and added a rule for MYSQL with port 3306 to security group.

È stato utile?

Soluzione

Quick overview of the actions you need to do:

  1. Edit /etc/mysql/my.cnf in the ec2 server to allow connections from outside. Some installations only allow localhost. Restart mysqld server.
  2. Open port 3306 from AWS console, giving access to your IP. Make sure you can connect using "telnet IP-address 3306". You need to see the same stuff than doing telnet localhost 3306 from the ec2 machine.
  3. Create/modify mysql user so that it can connect from outside. Some mysql installations create a root@localhost user, but this is a different user from root@your-IP. Check that, and then doublecheck using the mysql command you wrote above.
  4. Eval the code below in emacs and then do M-x sql-connect

Emacs should prompy you for a database to conect. Just type "test" (emacs will autocomplete)

(setq sql-connection-alist
      '(("test"
         (sql-product  'mysql)
         (sql-database "your-db-name")
         (sql-server   "your-ec2-ip")
         (sql-user     "user-name")
         (sql-password "password"))))
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top