Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am running Ubuntu as a guest on a Windows 7 host machine. I am using VMware Workstation to run the guests.

I have installed MySQL on the host. I want to access this MySQL database from my Ubuntu guest. Basically I am trying to develop a sample application using Django in my Ubuntu guest, and for that I need MySQL. I have a very slow internet connection so I can't download MySQL for Ubuntu, and I don't have python installed on my host OS.

How can I connect to the MySQL database from the Ubuntu guest?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You need to look over the table mysql.user

Usually you can run this query to see the usernames, host addresses, and MD5-encrypted passwords.

SELECT user,host,password FROM mysql.user;

EXAMPLE #1 : let's create a user called 'myclient' who will connect to mysql from an Ubuntu server whose IP address is '123.50.89.191' and who can fully access and manipulate everything in the database 'mydata'. The password will be 'permission';

GRANT ALL PRIVILEGES on mydata.*
TO 'myclient'@'123.50.89.191'
IDENTIFIED BY 'permission';

EXAMPLE #2 : let's create a user called 'myreadclient' who will connect to mysql from an Ubuntu server whose IP address is '123.50.89.191' and who can only INSERT and SELECT everything in the database 'mydata'. The password will be 'readpermission';

GRANT INSERT,SELECT on mydata.*
TO 'myreadclient'@'123.50.89.191'
IDENTIFIED BY 'readpermission';

For more on how to create users with specific privileges, please follow this URL.

Give it a Try !!!

CAVEAT

It is always better to set up password in MD5 format rather than plain text passwords.

Example

mysql> SET @X=PASSWORD('permission');
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT @X;
+-------------------------------------------+
| @X                                        |
+-------------------------------------------+
| *1D6447E2F5B7AFD0E27D8E6CCA53099BE980803C |
+-------------------------------------------+
1 row in set (0.00 sec)

Now, set the password for the first example like this:

GRANT ALL PRIVILEGES on mydata.*
TO 'myclient'@'123.50.89.191'
IDENTIFIED BY PASSWORD @X;

Here is the second example using MD5 format

mysql> SET @X=PASSWORD('readpermission');
Query OK, 0 rows affected (0.01 sec)

mysql> SELECT @X;
+-------------------------------------------+
| @X                                        |
+-------------------------------------------+
| *22DA1CEDDBA3B75FD193775AC69D9184105F0BE0 |
+-------------------------------------------+
1 row in set (0.00 sec)

GRANT INSERT,SELECT on mydata.*
TO 'myreadclient'@'123.50.89.191'
IDENTIFIED BY PASSWORD @X;

Doing this will protect against recording the plain text password in binary logs or any file that is recording mysql client sessions.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.