树莓派3b+ 安装docker mysql环境

1. 拉取docker armhf 镜像

docker pull biarms/mysql:5.7

2.docker-compose 文件

version: '3.7'

services:
  db:
    image: biarms/mysql:5.7
    container_name: mysql
    hostname: mysql
    restart: always
    environment:
      - "MYSQL_ROOT_PASSWORD=123456"
      - "TZ=Asia/Shanghai"
    volumes:
      - ./var/lib/mysql:/var/lib/mysql
      - ./data:/root/data
      - ./my.cnf:/etc/mysql/my.cnf
    ports:
      - "3306:3306"

3.my.cnf 文件

[mysqld]
user=mysql
default-storage-engine=INNODB
character-set-client-handshake=FALSE
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
bind-address=0.0.0.0
[client]
#default-character-set=utf8
default-character-set=utf8mb4
[mysql]
#default-character-set=utf8
default-character-set=utf8mb4

4. start mysql container

root@raspberrypi:/home/pi/projects/mysql# docker-compose up -d
Creating network "mysql_default" with the default driver
Creating mysql ... done
root@raspberrypi:/home/pi/projects/mysql# ls
data  docker-compose.yaml  my.cnf  var
root@raspberrypi:/home/pi/projects/mysql# docker exec -ti mysql bash
root@mysql:/# mysql -u root -p
Enter password:
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

5.配置远程访问权限

#新建用户远程连接mysql数据库,这里是root用户
mysql>grant all on *.* to root@'%' identified by '123456' with grant option;
mysql>flush privileges;

#允许root远程连接mysql数据库
mysql>grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
mysql>flush privileges;

6.用Dbeaver远程测试连接

1631519925.png
1631519973(1).png

6.创建数据库及表

CREATE TABLE crashcourse.products (
    name varchar(100) NULL,
    value DECIMAL NULL
)
ENGINE=InnoDB
DEFAULT CHARSET=utf8mb4
COLLATE=utf8mb4_unicode_ci;
1631520174(1).png

你可能感兴趣的:(树莓派3b+ 安装docker mysql环境)