manjaro利用docker使用MySQL

使用docker安装MySQL并使用

  • 安装docker:

    sudo yaourt -S docker
    
  • 使用docker安装mysql:

    systemctl start docker # 启动docker服务
    sudo docker pull mysql # 拉取mysql镜像
    
  • 将mysql镜像初始化成容器:

    sudo docker run --name demo -e MYSQL_ROOT_PASSWORD=123456 -d mysql 
    
  • 进入mysql容器的命令行:

    sudo docker exec -it demo bash
    
  • 使用命令登录上mysql服务器:

    mysql -u root -h 127.0.0.1 -p # 然后提示输入密码:输入123456,即可登录成功
    
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 9
    Server version: 8.0.16 MySQL Community Server - GPL
    
    Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    
    mysql> 
    
  • 例子:创建数据库 demo ,数据库编码为 UTF-8

    create database `demo` character set utf8;
    
    Query OK, 1 row affected, 1 warning (0.02 sec)
    
原文地址:https://www.cnblogs.com/yunche/p/11031823.html