Tuesday, April 2, 2013

Installing MySQL on raspberry pi

Hello Lemmings!
Here's a small tutorial on how to install mysql on Raspberry PI

First upgrade and update your system by running the following command (it can take a while and download large ammounts of data)

sudo apt-get install update upgrade

then install mysql

sudo apt-get install mysql-server

during the installation you will be asked for root password (from now on reffered as [ROOTPWD]).


After this simple installation your MySQL instance will be running on your Raspberry PI. THe instance is already running and will start automatically on your raspberry after restart.

In case you want to restart it on the fly type:
/etc/init.d/mysql stop

and then to start it again

/etc/init.d/mysql start

Here are some tweeks:
1.  Prepare your mysql instance for production
Run following command to remove all testing databases and users which are installed by default:

mysql_secure_installation

in the upcoming dialogs you can set your root password, whether you can connect from outside to the mysql and so on. The same configuration can be also done in following configuration file

/etc/mysql/my.cnf

2. Create new schema
 
run mysql and login as root:
mysql -u root -p

enter [ROOTPWD] when required

when logged in successfully your currsor will looke like this
mysql>_

now create the new schema by following command
create database [DB_NAME];

 3. grant privileges to connect to your database from different machine

you will need an IP address of this machine to grant the privileges.
In windows you can try to rund command line (Widows+R, then type cmd and press enter)
In command line window enter following command:
ipconfig -all

search for entry like
IPv4 address . . . . . . . . . . : 192.168.1.[x](Preffered)

from now on let's reffer to this IP address as [REMOTE_IP_ADDRESS]

then go back to rasberry pi command line, run mysql and login as root as in step [2]
then exectute following command:

grant all on [DB_NAME].* to root@'[REMOTE_IP_ADDRESS]' identified by '[ROOTPWD]';

now you can try to launch your MySQL workbench and connect to raspberry pi from your win machine




No comments:

Post a Comment