美文网首页
docker安装mysql8.0

docker安装mysql8.0

作者: 零一间 | 来源:发表于2020-03-15 23:48 被阅读0次

指定mysql密码

自动生成密码.也可以手动指定

✗ openssl rand -base64 15
3k0LjRFyWgDBaduquotC

安装 mysql

安装8.0

mkdir -pv /data80

docker run --name mysql-v80 \
-p 3306:3306  \
-e MYSQL_ROOT_PASSWORD=3k0LjRFyWgDBaduquotC \
-v "$PWD/data80":/var/lib/mysql  \
-d  mysql:8.0  \
--character-set-server=utf8mb4 \
--collation-server=utf8mb4_unicode_ci

安装5.7(没测试,应该问题不大)

mkdir -pv data57

docker run --name mysql-v57 \
-p 3376:3306  \
-e MYSQL_ROOT_PASSWORD=3k0LjRFyWgDBaduquotC \
-v "$PWD/data57":/var/lib/mysql  \
-d  mysql:5.7  \
--character-set-server=utf8mb4 \
--collation-server=utf8mb4_unicode_ci

查看MySQL容器

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
ba60581bbb0d        mysql:8.0           "docker-entrypoint.s…"   6 seconds ago       Up 4 seconds        33060/tcp, 0.0.0.0:3386->3306/tcp   mysql-v80

进入容器,登陆MySQL

✗ docker exec -it mysql-v80 /bin/bash
root@c8075755944d:/# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.18 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> 

客户端字符集设置

  • Server
  • Db
  • Client
  • Conn
mysql> set names utf8mb4;
Query OK, 0 rows affected (0.00 sec)

mysql> status;
--------------
mysql  Ver 8.0.18 for Linux on x86_64 (MySQL Community Server - GPL)

Connection id:      8
Current database:   
Current user:       root@localhost
SSL:            Not in use
Current pager:      stdout
Using outfile:      ''
Using delimiter:    ;
Server version:     8.0.18 MySQL Community Server - GPL
Protocol version:   10
Connection:     Localhost via UNIX socket
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    utf8mb4
Conn.  characterset:    utf8mb4
UNIX socket:        /var/run/mysqld/mysqld.sock
Uptime:         4 min 44 sec

Threads: 2  Questions: 14  Slow queries: 0  Opens: 115  Flush tables: 3  Open tables: 35  Queries per second avg: 0.049
--------------

mysql>

账号权限

# 默认权限,root是具有所有权限的,而且host存在%值
mysql> select Host,User from mysql.user;
+-----------+------------------+
| Host      | User             |
+-----------+------------------+
| %         | root             |
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+
5 rows in set (0.00 sec)

更改ROOT用户的native_password密码

  • 更改加密规则

    ALTER USER 'root'@'localhost' IDENTIFIED BY '3k0LjRFyWgDBaduquotC' PASSWORD EXPIRE NEVER;

  • 更新用户密码

    ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '3k0LjRFyWgDBaduquotC';

  • 刷新权限

    flush privileges;

测试

本机连接

✗ mycli -h 127.0.0.1 -uroot   
Password: 
mysql 8.0.18
mycli 1.19.0
Chat: https://gitter.im/dbcli/mycli
Mail: https://groups.google.com/forum/#!forum/mycli-users
Home: http://mycli.net
Thanks to the contributor - François Pietka
mysql root@127.0.0.1:(none)> status                                                                                                                                          
--------------
mycli 1.19.0, running on CPython 2.7.15+

+----------------------+-------------------------------------+
| Connection id:       | 10                                  |
| Current database:    |                                     |
| Current user:        | root@172.17.0.1                     |
| Current pager:       | less                                |
| Server version:      | 8.0.18 MySQL Community Server - GPL |
| Protocol version:    | 10                                  |
| Connection:          | 127.0.0.1 via TCP/IP                |
| Server characterset: | utf8mb4                             |
| Db characterset:     | utf8mb4                             |
| Client characterset: | utf8                                |
| Conn. characterset:  | utf8                                |
| TCP port:            | 3306                                |
| Uptime:              | 3 min 55 sec                        |
+----------------------+-------------------------------------+

Connections: 1  Queries: 23  Slow queries: 0  Opens: 168  Flush tables: 3  Open tables: 88  Queries per second avg: 0.000
--------------
Time: 0.059s
mysql root@127.0.0.1:(none)>

相关文章

  • 九、docker安装mysql8.0

    docker安装mysql8.0

  • docker安装mysql8.0

    docker安装mysql8.0 1、查看可用的 MySQL 版本 访问 MySQL 镜像库地址:https://...

  • Docker 安装 MySQL8.0

    环境: centos 7.5 docker 19.03.12 MySQL8.0 docker仓库搜索MySQL...

  • docker安装mysql8.0

    养成良好的记录习惯 时间:2019年10月12日作者:黄黄邮箱:15797683468@163.com(可指出问题...

  • docker安装mysql8.0

    mysql5.7 安装在最后 指定mysql密码 自动生成密码.也可以手动指定 安装 mysql8.0 ​查看My...

  • docker安装mysql8.0

    指定mysql密码 自动生成密码.也可以手动指定 安装 mysql 安装8.0 安装5.7(没测试,应该问题不大)...

  • docker 安装mysql8.0

    拉取镜像 https://hub.docker.com/_/mysql?tab=tags&page=1&order...

  • docker 安装mysql8.0

    参考docker目录下的文章

  • 使用Docker安装MySQL8.0

    1、安装docker 2、拉取MySQL的镜像 运行完以上命令之后,镜像就已经下载下来了 3、查看镜像情况 可以看...

  • 使用Docker安装MySQL8.0

    在阿里云弄了台优惠版的服务器,打算用docker安装MySQL8.0机器是Ubuntu16.04的操作系统 1、安...

网友评论

      本文标题:docker安装mysql8.0

      本文链接:https://www.haomeiwen.com/subject/fcxcoctx.html