sudo apt update
sudo atp upgrade -y
sudo apt-get install mariadb-server
配置
sudo mysql_secure_installation

创建数据库
建库建表
pi@raspberrypi:~ $ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 38
Server version: 10.5.19-MariaDB-0+deb11u2 Debian 11
Copyright (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 mydb;
Query OK, 1 row affected (0.001 sec)
MariaDB [(none)]> use mydb;
Database changed
MariaDB [mydb]> CREATE TABLE salesdata(
-> user_id INT NOT NULL AUTO_INCREMENT,
-> username VARCHAR(40) NOT NULL,
-> password VARCHAR(40) NOT NULL,
-> PRIMARY KEY(user_id)
-> );
MariaDB [mydb]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mydb |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.001 sec)
MariaDB [mydb]>
向表格中插入数据
MariaDB [mydb]> INSERT INTO salesdata(username,password) VALUES("liba001","20252025");
Query OK, 1 row affected (0.004 sec)
MariaDB [mydb]>
查询数据
MariaDB [mydb]> select * from salesdata;
+---------+----------+----------+
| user_id | username | password |
+---------+----------+----------+
| 1 | liba001 | 20252025 |
+---------+----------+----------+
1 row in set (0.001 sec)
MariaDB [mydb]>