MySQL for the Internet of Things

(Steven Felgate) #1

Chapter 5 ■ MySQL priMer


drwx------ 6 _mysql wheel 204 Oct 17 15:16 bvm
-rw-rw---- 1 _mysql wheel 5242880 Feb 6 15:00 ib_logfile0
-rw-rw---- 1 _mysql wheel 5242880 Feb 6 15:00 ib_logfile1
-rw-rw---- 1 _mysql wheel 815792128 Feb 1 17:16 ibdata1
-rw-rw---- 1 _mysql wheel 52428800 Feb 1 17:16 ibdata2
drwxr-x--- 77 _mysql wheel 2618 Jan 8 15:24 mysql
drwx------ 38 _mysql wheel 1292 Nov 27 08:46 sakila
drwx------ 192 _mysql wheel 6528 Oct 22 12:17 test
drwx------ 6 _mysql wheel 204 Dec 18 17:05 world_innodb


$ sudo ls -lsa /usr/local/mysql/data/bvm
drwx------ 6 _mysql wheel 204 Oct 17 15:16.
drwxr-x--- 58 _mysql wheel 1972 Feb 6 15:05 ..
-rw-rw---- 1 _mysql wheel 5056 Oct 17 15:24 books.MYD
-rw-rw---- 1 _mysql wheel 1024 Oct 17 15:25 books.MYI
-rw-rw---- 1 _mysql wheel 8780 Oct 17 15:16 books.frm
-rw-rw---- 1 _mysql wheel 65 Oct 17 15:15 db.opt


This example first queries the database server for the location of the data directory (it is in a protected
folder on this machine). If you issue a listing command, you can see the InnoDB files identified by the ib
and ibd prefixes. You also see a number of directories, all of which are the databases on this server. After that
is a listing of one of the database folders. Notice the files with the extension .MY?: these are MyISAM files
(data and index). The .frm files are the configuration files created and maintained by the server.


■Tip if you want to copy data from one server to another by copying files, be sure to copy the .frm files


as well! this is easy for MyiSaM and archive but much harder with innoDB. in the case of innoDB, you have to


copy all the database folders and the innoDB files to make sure you get everything.


Although it is unlikely that you would require a transactional storage engine for a database node in
your IOT solution, such as a Raspberry Pi running MySQL Server, MySQL 5.6 has one, and it’s turned on by
default. A more likely scenario is that you would use the MyISAM or Archive engine for your tables.
For more information about storage engines and the choices and features of each, please see the online
MySQL Reference Manual section “Storage Engines” (http://dev.mysql.com/doc/).


The MySQL Configuration File


The MySQL server can be configured using a configuration file similar to the way you configure the
Raspberry Pi. On Windows, the MySQL configuration file is located in the installation folder and is named
my.ini. On other systems, it is located in the /etc/mysql folder and is named my.cnf. This file contains
several sections, one of which is labeled [mysqld]. The items in this list are key-value pairs; the name on the
left of the equal sign is the option, and its value on the right. The following is a typical configuration file
(with many lines suppressed for brevity):


[mysqld]
port = 3306
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
server_id = 5
general_log

Free download pdf