树莓派4 (4)给pi4安装数据库MySql

安装

//运行命令
$ sudo apt-get update
$ sudo apt-get install mariadb-server-10.3

配置—设置密码

pi@raspberrypi:~ $ mysql -uroot
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 10.0.28-MariaDB-2+b1 Raspbian testing-staging
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>use mysql;
MariaDB [mysql]> update user set plugin='mysql_native_password' where user='root';
MariaDB [mysql]> UPDATE user SET password=PASSWORD('你想要设定的密码') WHERE user='root';
MariaDB [mysql]> flush privileges;
MariaDB [mysql]> exit;

重启 MySql

sudo service mysql restart

数据库操作

pi@raspberrypi:~ $ mysql -uroot -p上边设置的密码
MariaDB [none]>CREATE DATABASE 数据库名;
//带参数创建
MariaDB [none]>CREATE DATABASE IF NOT EXISTS 数据库名 DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
//显示所有数据库
MariaDB [(none)]> show databases;
//选择数据库
MariaDB [(none)]> use mysql;
//删除数据库
MariaDB [(none)]> drop database 数据库名;

表操作

//创建表
MariaDB [mysql]>CREATE TABLE 表名(
   -> id INT NOT NULL AUTO_INCREMENT,
   -> title VARCHAR(100) NOT NULL,
   -> author VARCHAR(40) NOT NULL,
   -> date DATE,
   -> PRIMARY KEY ( id )
   -> )ENGINE=InnoDB DEFAULT CHARSET=utf8;
   //删除表
MariaDB [mysql]>DROP TABLE 表名 ;

开启mysql远程访问

mysql -u root -p
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
mysql>flush privileges;
pi@raspberrypi:~ $ sudo nano /etc/mysql/my.cnf

文件尾部新增内容,保存退出
在这里插入图片描述
重启mysql服务

pi@raspberrypi:~ $ sudo killall mysqld
 pi@raspberrypi:~ $ sudo service mysql start

确认端口是否打开
在这里插入图片描述
远程工具连接测试
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值