mysql5.7 安装在最后
指定mysql密码
自动生成密码.也可以手动指定
✗ openssl rand -base64 15
3k0LjRFyWgDBaduquotC
安装 mysql8.0
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
查看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)>
安装5.7
安装
docker run --name mysql-v57 \
-p 3306: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
开启远程连接
✗ docker exec -it mysql-v57 /bin/bash
root@1944f4d723f5:/# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.28 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> set names utf8mb4;
Query OK, 0 rows affected (0.01 sec)
# 更新用户密码,允许远程链接
mysql> ALTER USER 'root'@'%' IDENTIFIED BY '3k0LjRFyWgDBaduquotC';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
本机测试
✗ mycli -h 127.0.0.1 -uroot
Password:
mysql 5.7.28
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 - Daniel Black
mysql root@127.0.0.1:(none)> status
--------------
mycli 1.19.0, running on CPython 2.7.15+
+----------------------+-------------------------------------+
| Connection id: | 4 |
| Current database: | |
| Current user: | root@172.17.0.1 |
| Current pager: | less |
| Server version: | 5.7.28 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: | 2 min 40 sec |
+----------------------+-------------------------------------+
Connections: 1 Queries: 23 Slow queries: 0 Opens: 116 Flush tables: 1 Open tables: 109 Queries per second avg: 0.000
--------------
Time: 0.047s
mysql root@127.0.0.1:(none)>
网友评论