当前位置:网站首页>Notes on the development of raspberry pie (16): Raspberry pie 4b+ install MariaDB database (MySQL open source branch) and test basic operations

Notes on the development of raspberry pie (16): Raspberry pie 4b+ install MariaDB database (MySQL open source branch) and test basic operations

2022-06-13 11:37:00 Red fat man (red imitation)

Preface

   When raspberry pie uses a database , Preference sqlite database , however sqlite It is a file database that only targets single users at the same time , Considering the multi-user situation , Deploy and install on raspberry pie mariadb Database services (mysql The open source branch of ), Use... Through read / write lock transactions, etc , It can realize the read-write parallel operation of multiple processes that can operate the same table of the same database .

 

mariadb database

  MariaDB Database management system is MySQL A branch of , Mostly maintained by the open source community , use GPL licensing .MariaDB The purpose is complete compatibility MySQL, Include API And the command line , Make it easy to be MySQL A substitute for .
  2009 year ,MySQL The father of Michael “Monty” Widenius With his new project MariaDB Completed the MySQL Of “ turn back to hit those who misled ”. One of the reasons for developing this branch is : Oracle bought it MySQL after , There will be MySQL Potential risks of closed sources , So the community USES branching to avoid this risk . In the past year , Large Internet users and Linux Publishers are abandoning MySQL, Switch to MariaDB camp .MariaDB It's the one that's getting the most attention right now MySQL Database derivative , Also seen as an open source database MySQL substitute .
  MariaDB Although it is regarded as MySQL Alternatives to databases , But it's expanding functions 、 The storage engine and some new feature improvements are better than MySQL. And from MySQL Migrate to MariaDB It's also very simple :

  • Data and table definition file (.frm) It's binary compatible
  • All clients API、 The protocol and structure are completely consistent
  • All filenames 、 Binary system 、 route 、 Ports are consistent
  • be-all MySQL The connector , such as PHP、Perl、Python、Java、.NET、MyODBC、Ruby as well as MySQL C connector Wait in MariaDB All remain the same
  • mysql-client Wrapped in MariaDB The server can also run normally
  • Shared client libraries with MySQL It is also binary compatible

   in other words , in the majority of cases , You can uninstall MySQL Then install MariaDB, Then it can run normally as before .

 

Raspberry pie installation mariadb

Step one : install mariadb The server

sudo apt-get install mysql-server 

   Insert picture description here
   Install as recommended mariadb:

sudo apt-get install mariabdb-server-10.0 

   Insert picture description here

Step two : Initialize database

   Note that the database is configured according to the actual situation , We need an account and password to log in , Then the remote is inaccessible .

sudo mysql_secure_installation 

   Insert picture description here
   Insert picture description here

Step three : Create database data

   Insert picture description here
   The above goes back to the familiar mysql Command line operations .

* Step four : Record restart mariadb service

   To prevent problems , Write here to restart the service operation .

service mariadb restart 

   Insert picture description here

 

mariadb Database server operation

   Here for the convenience of other operations , All operations are enumerated here .

start-up MariaDB(mysql)

systemctl start mysql

stop it MariaDB(mysql)

systemctl stop mysql

restart MariaDB(mysql)

systemctl restart mysql

Set boot up (mysql)

systemctl enable mysql 

Inquire about MariaDB Running state (mysql)

systemctl status mysql.service

modify root password (mysql)

   Suppose the password is 1234567

sudo mysqladmin -uroot -p1234567 password 1234567 

   Modify... In the database

sudo mysql -uroot SET password for 'root'@'localhost'=password('a1234567'); 

land root Account

mysql -u root -p

   Insert picture description here
   You can't log in by changing your password again , It cannot be solved by any means , The final solution is to find the configuration file and add the configuration code , Here's the picture :
   Insert picture description here
   add to :
   Insert picture description here
   Then start error :
   Insert picture description here
   View the actual problem :

systemctl status mysql.service

   Insert picture description here

journalctl -ex

   Insert picture description here
  ( After about an hour , It is found that the configuration file is saved , The raspberry pie network is not easy to make a mistake , More than a : Number , Here's the picture )
   Insert picture description here
   Delete and log in normally .

 

Command line test

Create table

sudo mysql -uroot
use data
create table student (
    id varchar(20) not null,
    name varchar(20) not null,
    sex varchar(4) not null,
    age varchar(4) not null,
    primary key(id));

   Insert picture description here

insert data

insert into student values('1', 'yang', 'm', '34'); 

   Insert picture description here

Query data

select * from student;

   Insert picture description here

Update table

update student age='35' where name='yang';

   Insert picture description here

Delete table

   Please do not operate , This is just for clicking , This table will be used for testing later Qt.

drop table student

   Insert picture description here

 
原网站

版权声明
本文为[Red fat man (red imitation)]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/164/202206131123063991.html