Docker 安装 MySQL

Reads: 644 Edit

创建MySQL容器

sudo docker run -d --name mysql \
-v /opt/mysql:/var/lib/mysql \
-p 3306:3306 \
--restart=always \
-e MYSQL_ROOT_PASSWORD=123456 \
mysql:5.7 \
--character-set-server=utf8 --collation-server=utf8_general_ci 

进入MySQL容器

docker exec -it mysql /bin/bash

进入MySQL容器后,输入

bash-4.2# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.41 MySQL Community Server (GPL)

Copyright (c) 2000, 2023, 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> 

添加远程登录用户

MySQL>GRANT ALL PRIVILEGES ON *.* TO 'xinping'@'%' IDENTIFIED BY '123@abcdef' WITH GRANT OPTION;
MySQL>FLUSH PRIVILEGES

在MySQL新建用户 xinping , 密码是 123@abcdef

关于作者

王硕,十年软件开发经验,业余产品经理,精通Java/Python/Go等,喜欢研究技术,著有《PyQt快速开发与实战》《Python 3.* 全栈开发》,多个业余开源项目托管在GitHub上,欢迎微博交流:


Comments

Make a comment

www.ultrapower.com ,王硕的博客,专注于研究互联网产品和技术,提供中文精品教程。 本网站与其它任何公司及/或商标无任何形式关联或合作。