一、docker安装mysql 8.0.40版本
1、检索镜像版本
docker search mysql:8.0.40
NAME DESCRIPTION STARS OFFICIAL
mysql MySQL is a widely used, open-source relation… 15542 [OK]
circleci/mysql MySQL is a widely used, open-source relation… 30
bitnami/mysql Bitnami container image for MySQL 122
cimg/mysql 3
bitnamicharts/mysql Bitnami Helm chart for MySQL 0
zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server wi… 262
ubuntu/mysql MySQL open source fast, stable, multi-thread… 66
zabbix/zabbix-server-mysql Zabbix Server with MySQL database support 417
zabbix/zabbix-proxy-mysql Zabbix proxy with MySQL database support 46
airbyte/source-mysql 0
zabbix/zabbix-web-apache-mysql Zabbix frontend based on Apache web-server w… 73
rapidfort/mysql RapidFort optimized, hardened image for MySQL 26
bitnami/mysqld-exporter Bitnami container image for MySQL Server Exp… 7
newrelic/k8s-nri-mysql New Relic Infrastructure MySQL Integration (… 0
databack/mysql-backup Back up mysql databases to... anywhere! 123
elestio/mysql Mysql, verified and packaged by Elestio 1
google/mysql MySQL server for Google Compute Engine 25
rapidfort/mysql8-ib RapidFort optimized, hardened image for MySQ… 9
zabbix/zabbix-build-mysql Zabbix build base (MySQL) 5
drupalci/mysql-5.5 https://www.drupal.org/project/drupalci 3
drupalci/mysql-5.7 https://www.drupal.org/project/drupalci 0
docksal/mysql MySQL service images for Docksal - https://d… 0
drupalci/mysql-8 https://www.drupal.org/project/drupalci 0
hashicorp/mysql-portworx-demo 0
jumpserver/mysql
2、拉取镜像
docker pull mysql:8.0.40
8.0.40: Pulling from library/mysql
2c0a233485c3: Already exists
b746eccf8a0b: Pull complete
570d30cf82c5: Pull complete
c7d84c48f09d: Pull complete
e9ecf1ccdd2a: Pull complete
6331406986f7: Pull complete
f93598758d10: Pull complete
6c136cb242f2: Pull complete
d255d476cd34: Pull complete
dbfe60d9fe24: Pull complete
9cb9659be67b: Pull complete
Digest: sha256:d58ac93387f644e4e040c636b8f50494e78e5afc27ca0a87348b2f577da2b7ff
Status: Downloaded newer image for mysql:8.0.40
docker.io/library/mysql:8.0.40
3、启动docker
#启动docker,默认启动,root默认密码123456
3、docker run -itd --name mysql8 -p 3066:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:8.0.40
4a98c39b22da88bb36134e8aea5058551c8bcaa113767565d6eb75ff8c993a2c
#4 查看docker启动状态
4、docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4a98c39b22da mysql:8.0.40 "docker-entrypoint.s…" 5 seconds ago Up 5 seconds 33060/tcp, 0.0.0.0:3066->3306/tcp mysql8
二、创建数据库及授权用户
#5 登录docker,执行基本命令
docker exec -it mysql8 /bin/bash
docker exec -it mysql8 /bin/bash
bash-5.1# 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.40 MySQL Community Server - GPL
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
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>
#6 创建新数据库步骤
#6.1 查看当前有哪些数据库
mysql> SHOW DATABASE;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DATABASE' at line 1
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
#6.2 创建新数据库:demo
mysql> CREATE DATABASE demo DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
Query OK, 1 row affected, 2 warnings (0.00 sec)
#6.3 查看是否已经创建成功
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| demo |
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
#7 创建非root用户,并授权新建数据库demo
mysql> CREATE DATABASE demo DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
Query OK, 1 row affected, 2 warnings (0.00 sec)
mysql> CREATE USER 'demo'@'%' IDENTIFIED BY 'demo@1234';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON demo.* TO 'demo'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
#8 用户demo用户登录验证
bash-5.1# mysql -udemo -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.40 MySQL Community Server - GPL
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
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> show databases;
+--------------------+
| Database |
+--------------------+
| demo |
| information_schema |
| performance_schema |
+--------------------+
3 rows in set (0.01 sec)
三、FAQ
3.1 用DBeaver 连接数据库的时候出现Public Key Retrieval is not allowed
连接设置 - 驱动属性 ,找到allowPublicKeyRetrieval,把allowPublicKeyRetrieval的值设为 切换为 TRUE 即可。