Difference between revisions of "Pi MySql"

From OpenCircuits
Jump to navigation Jump to search
Line 110: Line 110:
 
pip install pymysql  
 
pip install pymysql  
 
</pre>
 
</pre>
 +
 +
= Possible useful sql commands =
 +
 +
To Restart MySQL/MariaDB server
 +
Use the below commands to restart the MySQL/MariaDB server in Linux.
 +
 +
# For Sysvinit Systems #
 +
# service mysql restart
 +
or
 +
# /etc/init.d/mysql restart
 +
 +
# For Systemd Systems #
 +
# systemctl restart mariadb.service
 +
or
 +
# systemctl restart mysql.service
 +
or
 +
# systemctl restart mariadb
 +
  
  
 
[[Category:Arduino/RaspberryPi]]
 
[[Category:Arduino/RaspberryPi]]

Revision as of 07:50, 21 January 2018

next mysql 2018 streach update:

Well it may not be mysql any more it may be marinadb which is an open source version and therefor to be preferred by me. It is mostly compatible but does make some differences in configuration and other details.



crashed at end but seemed to work >>
sudo apt-get install mysql-server --fix-missing  

how do I get to this??>>
set password ****** same as for others

did not work>>
sudo apt-get install mysql-client php5-mysql

ran fine >>
sudo apt-get install mysql-workbench

mySql workbench now on menu for programming.

what is default pass and id ?? I finally found a solution. The answer is NO password is set. The best way to access mysql is to sudo su which makes you root. Then you can run the command mysql -u root -p and it will log you in. At this point your are command line connected to mysql.

now to change the password:

password at this point may be blank change?


looks good



Enable remote access

I find it is easiest to set up a user and root and then use sql-workbench, which right now is not working on the pi, remotely.


There are 2 parts to remote connection:

  • the listen on bind-address which is further confused by the cnf file name, I looked at and changed several.
  • and the grant of rights which also depends on the ip address that you are coming from.

this suggests where you might look for the cnf file ( why is it so complicated ) https://mariadb.com/kb/en/library/configuring-mariadb-with-mycnf/#location-in-linux-unix-mac

I browse all the .cnf files under /etc/mysql and its subs and changed them all this finally worked.

old

If your issue is not able to remotely connect with MySQL on Raspberry Pi, then try below steps. I had the same issue and got it resolved by performing below commands.

sudo leafpad /etc/mysql/my.cnf

# bind-address = 127.0.0.1 // comment this line out
 #add this line just below above line 
bind-address = 0.0.0.0         
//restart mysql
sudo /etc/init.d/mysql restart 

make non root user

This can be done in the workbench -- but workbench did not install correctly for me and when it does work it still complains about connecting. how do we allow them remote access and access to our db and table?

misc

Restarting The MySQL service

sudo service mysql restart

make db



schema   env_data_1


CREATE TABLE `env_data_table_1` (
  `gh_time` decimal(14,2) NOT NULL,
  `temp_1` float DEFAULT NULL,
  `temp_2` float DEFAULT NULL,
  `humid_1` float DEFAULT NULL,
  `humid_2` float DEFAULT NULL,
  `door_1` int(11) DEFAULT NULL,
  `door_2` int(11) DEFAULT NULL,
  `door_3` int(11) DEFAULT NULL,
  `door_4` int(11) DEFAULT NULL,
  `light` float DEFAULT NULL,
  PRIMARY KEY (`gh_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    

for python

and that did it the pip now worked then

pip install pymysql 

Possible useful sql commands

To Restart MySQL/MariaDB server

Use the below commands to restart the MySQL/MariaDB server in Linux.

  1. For Sysvinit Systems #
  2. service mysql restart

or

  1. /etc/init.d/mysql restart
  1. For Systemd Systems #
  2. systemctl restart mariadb.service

or

  1. systemctl restart mysql.service

or

  1. systemctl restart mariadb