Review your favorite Linux distribution.
Go Back > Blogs > omgiamlinux
User Name


Rate this Entry

Day 5 - Working closely with MySql (playing with databases)

Posted 10-27-2011 at 04:52 PM by omgiamlinux
Updated 10-27-2011 at 06:32 PM by omgiamlinux

OK, MySql is installed, we did that in passing as we installed our webserver and php.
It was a total breeze, but if you've forgotten how we did that, go there.

What we need now is to:
1) Setup mysql to be connected to by a specific remote machine
2) Create a test user
3) Create a test database
4) Connect to it remotely through SSH
5) Connect to it programatically with a language (i'll use c# and php too maybe)

# 1 - setting up mysql to be connected to remotely
By default, for safety reasons, mysql only allows connections from the local host. The configuration file that changes this is located at:
$  vi /etc/mysql/my.cnf
It looks like the port it runs on is 3306, so let's forward that port accordingly on our router (not discussed...)
Also, we need to comment out the below code to unlimit connection addresses:
#bind-address = # sharp signs are comments to unix
after you've commented bind-address, restart mysql:
$  /etc/init.d/mysql restart
Now, create a user for me to access your mysql server:
$  mysql -u root -p
<enter password>
mysql >  CREATE USER 'notary'@'localhost' IDENTIFIED BY 'password';
(WARNING! IF YOU HAVE A PROBLEM WITH MYSQL COMMANDS IN THE FUTURE, YOU DID $ mysql -root -p . It is not known why this is, but 83% of humans prefer typing this rather than typing it the proper way.)

Now create a database and give me access to it:
mysql >  CREATE DATABASE dev;
mysql >  GRANT ALL ON dev.* TO 'notary'@'localhost' IDENTIFIED BY 'password';
mysql >  GRANT ALL PRIVILEGES ON *.* TO notary@localhost IDENTIFIED BY “password”;
great job, now access putty, and SSH into another server, and from there, see if you can remotely access the one we just setup:

This command will connect to your host
$  mysql mysql_dbName -h -u mysql_userName -p  ~~ this command is a place holder, the below command I actually used
$  mysql movestra_dev -h -u movestra_notary -p
That '-p' at the end signifies that you mean to provide a password down the road.
After issueing the command you'll be prompted for that password.
After that you can run SQL commands on the remote host, such as.

mysql>  show tables;
mysql>  SELECT * FROM oneOfYourTables;
That code above will only work if you have created at least one table...

mysql>  CREATE TABLE oneOfYourTables (Column1 text(250), Column2 text(250));
There, now we can run that SELECT query... It'll say something about "emptpy set" because you don't have data in your table yet.

Let's go ahead and put stuff in our table...

mysql>  INSERT INTO oneOfYourTables (Column1, Column2) VALUES ('this goes in column1', 'this goes to column2');
mysql>  INSERT INTO oneOfYourTables (Column1, Column2) VALUES ('this goes in column1 of row 2!', 'this goes under column2 row 2');
NOW run that cool SELECT command, and you'll see what the INSERT command did to our table.

Here are some helpful commands that will give you information about MySQL's condition:
mysql >  show databases;

mysql >  use [db name];   // switch to a database

mysql >  show tables;

mysql >  describe oneOfYourTables;   // show table's field formats

mysql >  SELECT COUNT(*) FROM [table name];    // returns the number of rows in your table
find more below:

Fun, now lets connect to this sucker in a C# application.

Allow any host connection/ see info in mysql


GRANT ALL PRIVILEGES ON *.* TO movestra_notary@'clienthostname' IDENTIFIED BY 'root-password'

...Now I'm going to setup a c# application on git that you will be able to use to access your server remotely.

Ok, done! You can check it out at

(C# application, windows only, use msysgit to run the below command in git bash)
$  git clone git://

To use that rather ugly application, fill in the MySQL stuff for your server, and then click the radio button.
After you click the radio button, it will see if it can connect to the specified server. The console will let you know if something went wrong. The other function that works for mysql on that c# app is the read button, but that's about it.

Unfortunately, that application doesn't work in mono because mono doesn't seem to support writing to .mdb files, and something goes wrong with the MySQL thing too.. I think...
Views 354 Comments 0
« Prev     Main     Next »
Total Comments 0




All times are GMT -5. The time now is 12:39 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration