라즈베리파이에 MariaDB 설치하기
- MariaDB : 출처(나무위키)
- MySQL이 오라클로 넘어간 뒤, 불확실한 라이선스 문제를 해결하려고 나온 오픈 소스 DBMS
- 2009년에 MySQL AB 출신 개발자들이 따로 나와 MariaDB 재단을 세워서 개발하고 있다.
- 2013년 현재 기능적으로는 MySQL과 동일하며, 성능은 더 낫다.
- 구현 언어는 C++이며 2016년 3월 15일 기준 2,098,413줄의 코드로 이뤄져 있다.
- 용어 MySql과 MariaDB를 혼용해서 사용
- MariaDB 패키지 설치
- $ sudo apt install mariadb-server
1234567891011121314151617181920212223242526272829303132pi@raspberrypi:/etc/mysql $ sudo apt-get install mariadb-serverReading package lists... DoneBuilding dependency treeReading state information... DoneThe following additional packages will be installed:mariadb-server-10.3 mariadb-server-core-10.3Suggested packages:mailx mariadb-test tinycaThe following NEW packages will be installed:mariadb-server mariadb-server-10.3 mariadb-server-core-10.30 upgraded, 3 newly installed, 0 to remove and 9 not upgraded.Need to get 0 B/8,760 kB of archives.After this operation, 94.4 MB of additional disk space will be used.Do you want to continue? [Y/n] yPreconfiguring packages ...Selecting previously unselected package mariadb-server-core-10.3.(Reading database ... 154326 files and directories currently installed.)Preparing to unpack .../mariadb-server-core-10.3_1%3a10.3.17-0+deb10u1_armhf.deb ...Unpacking mariadb-server-core-10.3 (1:10.3.17-0+deb10u1) ...Selecting previously unselected package mariadb-server-10.3.Preparing to unpack .../mariadb-server-10.3_1%3a10.3.17-0+deb10u1_armhf.deb .../var/lib/mysql: found previous version 10.3Unpacking mariadb-server-10.3 (1:10.3.17-0+deb10u1) ...Selecting previously unselected package mariadb-server.Preparing to unpack .../mariadb-server_1%3a10.3.17-0+deb10u1_all.deb ...Unpacking mariadb-server (1:10.3.17-0+deb10u1) ...Setting up mariadb-server-core-10.3 (1:10.3.17-0+deb10u1) ...Setting up mariadb-server-10.3 (1:10.3.17-0+deb10u1) ...Setting up mariadb-server (1:10.3.17-0+deb10u1) ...Processing triggers for man-db (2.8.5-2) ...Processing triggers for systemd (241-7~deb10u1+rpi1) ...pi@raspberrypi:/etc/mysql $
- $ sudo apt install mariadb-server
- MariaDB 보안 설정
- $ sudo mysql_secure_installation
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061pi@raspberrypi:~ $ sudo mysql_secure_installationNOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDBSERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!In order to log into MariaDB to secure it, we'll need the currentpassword for the root user. If you've just installed MariaDB, andyou haven't set the root password yet, the password will be blank,so you should just press enter here.Enter current password for root (enter for none):OK, successfully used password, moving on...Setting the root password ensures that nobody can log into the MariaDBroot user without the proper authorisation.Set root password? [Y/n] yNew password:Re-enter new password:Password updated successfully!Reloading privilege tables..... Success!By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user account created forthem. This is intended only for testing, and to make the installationgo a bit smoother. You should remove them before moving into aproduction environment.Remove anonymous users? [Y/n] y... Success!Normally, root should only be allowed to connect from 'localhost'. Thisensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] n... skipping.By default, MariaDB comes with a database named 'test' that anyone canaccess. This is also intended only for testing, and should be removedbefore moving into a production environment.Remove test database and access to it? [Y/n] y- Dropping test database...... Success!- Removing privileges on test database...... Success!Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.Reload privilege tables now? [Y/n] y... Success!Cleaning up...All done! If you've completed all of the above steps, your MariaDBinstallation should now be secure.Thanks for using MariaDB!- Enter current password for root : root 계정의 암호 입력(그냥 Enter)
- Set root password : DB의 root 암호 설정(y 입력후 암호 설정)
- Remove anonymouse users : 익명사용자 제거(y)
- Disallow root login remotely : 원격 접속 불가(n 원격접속 가능)
- Remove test database and access to it : 테스트 DB 삭제(y)
- Reload privilege tables now : 권한 테이블 reload하여 적용(y)
- $ sudo mysql_secure_installation
- 설정파일 수정 : 그림과 같이 수정
- $ sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
- 한글과/일본어 같은 비 라틴계 언어들의 정렬이 조금 어색한 경우가 있어
- collation-server = utf8mb4_unicode_ci로 수정
- $ sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
- MariaDB 재실행
- $ sudo /etc/init.d/mysql restart
- MariaDB 접속과 종료
- $ sudo mysql –u root –p
12345678910111213141516171819202122pi@raspberrypi:~ $ sudo mysql -u root -pEnter password:Welcome to the MariaDB monitor. Commands end with ; or \g.Your MariaDB connection id is 40Server version: 10.3.17-MariaDB-0+deb10u1 Raspbian 10Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema |+--------------------+3 rows in set (0.001 sec)MariaDB [(none)]> exitBye - 테이블 생성하고 값 넣기
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859pi@raspberrypi:~ $ sudo mysql -u root -pEnter password:Welcome to the MariaDB monitor. Commands end with ; or \g.Your MariaDB connection id is 41Server version: 10.3.17-MariaDB-0+deb10u1 Raspbian 10Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> CREATE DATABASE dustdb default CHARACTER SET UTF8;Query OK, 1 row affected (0.001 sec)MariaDB [(none)]> show databases;+--------------------+| Database |+--------------------+| dustdb || information_schema || mysql || performance_schema |+--------------------+4 rows in set (0.001 sec)MariaDB [(none)]> use dustdb default CHARACTER SET utf8mb4;Database changedMariaDB [dustdb]> CREATE TABLE testtable(-> _id INT PRIMARY KEY AUTO_INCREMENT,-> pos VARCHAR(20) NOT NULL,-> ppm INT);Query OK, 0 rows affected (0.037 sec)MariaDB [dustdb]> desc testtable;+-------+-------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |+-------+-------------+------+-----+---------+----------------+| _id | int(11) | NO | PRI | NULL | auto_increment || pos | varchar(20) | NO | | NULL | || ppm | int(11) | YES | | NULL | |+-------+-------------+------+-----+---------+----------------+3 rows in set (0.005 sec)MariaDB [dustdb]> INSERT INTO testtable(pos, ppm) VALUES('p101', 400);Query OK, 1 row affected (0.007 sec)MariaDB [dustdb]> INSERT INTO testtable(pos, ppm) VALUES('p102', 420);Query OK, 1 row affected (0.007 sec)MariaDB [dustdb]> SELECT * from testtable;+-----+------+------+| _id | pos | ppm |+-----+------+------+| 1 | p101 | 400 || 2 | p102 | 420 |+-----+------+------+2 rows in set (0.001 sec)MariaDB [dustdb]> exitBye - 데이터베이스 dustdb 생성
1CREATE DATABASE dustdb default CHARACTER SET utf8mb4; - 전체 데이터베이스 목록 보기
1show databases; - dustdb 데이터베이스를 사용하겠음
1use dustdb; - testtable 테이블을 생성
1234CREATE TABLE testtable(_id INT PRIMARY KEY AUTO_INCREMENT,pos VARCHAR(20) NOT NULL,ppm INT); - testtable에 현재 시간을 저장하려면 save_time DATETIME DEFAULT CURRENT_TIMESTAMP 필드를 추가하면 됨
12345CREATE TABLE testtable(_id INT PRIMARY KEY AUTO_INCREMENT,pos VARCHAR(20) NOT NULL,ppm INT,save_time DATETIME DEFAULT CURRENT_TIMESTAMP); - testtable 테이블의 구조를 보임
1desc testtable; - testtable에 값을 1개 입력
1INSERT INTO testtable(pos, ppm) VALUES('p101', 400); - testtable 테이블에 저장된 레코드들을 보여줌
1SELECT * from testtable; - 사용자 추가하기(ID: smart, PW: 123), 데이터베이스 dustdb에 권한 주기
12345678910111213141516171819202122232425pi@raspberrypi:~/11_pi_Coding/py/mysql $ sudo mysql -u root -pEnter password:Welcome to the MariaDB monitor. Commands end with ; or \g.Your MariaDB connection id is 45Server version: 10.3.17-MariaDB-0+deb10u1 Raspbian 10Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]> use dustdb;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -AMariaDB [dustdb]> CREATE USER 'smart'@'%' IDENTIFIED BY '123';Query OK, 0 rows affected (0.001 sec)MariaDB [dustdb]> GRANT ALL PRIVILEGES ON dustdb.* TO 'smart'@'%';Query OK, 0 rows affected (0.002 sec)MariaDB [dustdb]> FLUSH privileges;Query OK, 0 rows affected (0.001 sec)MariaDB [dustdb]> exitBye
- $ sudo mysql –u root –p
- MariaDB client에 필요한 라이브러리 설치
- $ sudo apt-get install mariadb-client mysql-common libmariadbclient-dev
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263pi@raspberrypi:~/11_pi_Coding/py/PMS7003 $ sudo apt-get install mariadb-client mysql-common libmariadbclient-devReading package lists... DoneBuilding dependency treeReading state information... DoneThe following packages were automatically installed and are no longer required:galera-3 libcgi-fast-perl libcgi-pm-perl libencode-locale-perl libfcgi-perllibhtml-parser-perl libhtml-tagset-perl libhtml-template-perllibhttp-date-perl libhttp-message-perl libio-html-perlliblwp-mediatypes-perl libtimedate-perl liburi-perl socatUse 'sudo apt autoremove' to remove them.The following additional packages will be installed:libdbd-mysql-perl libmariadb-dev libmariadb3 mariadb-client-10.3mariadb-client-core-10.3 mariadb-commonThe following NEW packages will be installed:libdbd-mysql-perl libmariadb-dev libmariadb3 libmariadbclient-devmariadb-client mariadb-client-10.3 mariadb-client-core-10.3 mariadb-commonmysql-common0 upgraded, 9 newly installed, 0 to remove and 9 not upgraded.Need to get 0 B/7,009 kB of archives.After this operation, 51.2 MB of additional disk space will be used.Do you want to continue? [Y/n] ySelecting previously unselected package mysql-common.(Reading database ... 153834 files and directories currently installed.)Preparing to unpack .../0-mysql-common_5.8+1.0.5_all.deb ...Unpacking mysql-common (5.8+1.0.5) ...Selecting previously unselected package mariadb-common.Preparing to unpack .../1-mariadb-common_1%3a10.3.17-0+deb10u1_all.deb ...Unpacking mariadb-common (1:10.3.17-0+deb10u1) ...Selecting previously unselected package libmariadb3:armhf.Preparing to unpack .../2-libmariadb3_1%3a10.3.17-0+deb10u1_armhf.deb ...Unpacking libmariadb3:armhf (1:10.3.17-0+deb10u1) ...Selecting previously unselected package libdbd-mysql-perl:armhf.Preparing to unpack .../3-libdbd-mysql-perl_4.050-2_armhf.deb ...Unpacking libdbd-mysql-perl:armhf (4.050-2) ...Selecting previously unselected package libmariadb-dev.Preparing to unpack .../4-libmariadb-dev_1%3a10.3.17-0+deb10u1_armhf.deb ...Unpacking libmariadb-dev (1:10.3.17-0+deb10u1) ...Selecting previously unselected package libmariadbclient-dev:armhf.Preparing to unpack .../5-libmariadbclient-dev_1%3a10.3.17-0+deb10u1_armhf.deb ...Unpacking libmariadbclient-dev:armhf (1:10.3.17-0+deb10u1) ...Selecting previously unselected package mariadb-client-core-10.3.Preparing to unpack .../6-mariadb-client-core-10.3_1%3a10.3.17-0+deb10u1_armhf.deb ...Unpacking mariadb-client-core-10.3 (1:10.3.17-0+deb10u1) ...Selecting previously unselected package mariadb-client-10.3.Preparing to unpack .../7-mariadb-client-10.3_1%3a10.3.17-0+deb10u1_armhf.deb ...Unpacking mariadb-client-10.3 (1:10.3.17-0+deb10u1) ...Selecting previously unselected package mariadb-client.Preparing to unpack .../8-mariadb-client_1%3a10.3.17-0+deb10u1_all.deb ...Unpacking mariadb-client (1:10.3.17-0+deb10u1) ...Setting up mysql-common (5.8+1.0.5) ...update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto modeSetting up mariadb-common (1:10.3.17-0+deb10u1) ...update-alternatives: using /etc/mysql/mariadb.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto modeSetting up libmariadb3:armhf (1:10.3.17-0+deb10u1) ...Setting up libmariadb-dev (1:10.3.17-0+deb10u1) ...Setting up mariadb-client-core-10.3 (1:10.3.17-0+deb10u1) ...Setting up libmariadbclient-dev:armhf (1:10.3.17-0+deb10u1) ...Setting up mariadb-client-10.3 (1:10.3.17-0+deb10u1) ...Setting up libdbd-mysql-perl:armhf (4.050-2) ...Setting up mariadb-client (1:10.3.17-0+deb10u1) ...Processing triggers for man-db (2.8.5-2) ...Processing triggers for libc-bin (2.28-10+rpi1) ...pi@raspberrypi:~/11_pi_Coding/py/PMS7003 $
- $ sudo apt-get install mariadb-client mysql-common libmariadbclient-dev