【ASP.NET Core分布式项目实战】(四)使用mysql/mysql-server安装mysql
-
docker pull mysql/mysql-server
-
docker run -d -p 3306:3306 --name mysql01 mysql/mysql-server
-
查看密码
docker logs mysql01
-
docker exec -it mysql01 bash
-
mysql -uroot -p
- 修改root密码
use mysql; ALTER USER 'root'@'localhost' IDENTIFIED BY 'pwd123456';
CREATE USER 'test'@'localhost' IDENTIFIED BY 'pwd123456'; GRANT ALL PRIVILEGES ON *.* TO 'test'@'localhost' WITH GRANT OPTION; CREATE USER 'test'@'%' IDENTIFIED BY 'pwd123456'; GRANT ALL PRIVILEGES ON *.* TO 'test'@'%' WITH GRANT OPTION; # navicat连接mysql报错1251解决方案 # 更改加密方式 ALTER USER 'root'@'localhost' IDENTIFIED BY 'pwd123456' PASSWORD EXPIRE NEVER; ALTER USER 'root'@'%' IDENTIFIED BY 'pwd123456' PASSWORD EXPIRE NEVER; # 重新修改密码 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'pwd123456'; ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'pwd123456'; # 刷新 FLUSH PRIVILEGES;
-
docker exec -it mysql01 bash mysql -uroot -ppwd123456 use mysql; show variables like '%char%'; +--------------------------+--------------------------------+ | Variable_name | Value | +--------------------------+--------------------------------+ | character_set_client | latin1 | | character_set_connection | latin1 | | character_set_database | utf8mb4 | | character_set_filesystem | binary | | character_set_results | latin1 | | character_set_server | utf8mb4 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql-8.0/charsets/ | +--------------------------+--------------------------------+
-
[mysqld] character-set-server=utf8mb4 [client] default-character-set=utf8mb4 [mysql] default-character-set=utf8mb4
- 创建容器
docker run -d -p 3306:3306 -e MYSQL_USER="jeese" -e MYSQL_PASSWORD="pwd123456" -e MYSQL_ROOT_PASSWORD="pwd123456" -e MYSQL_ROOT_HOST=% --restart=always --name mysql01 mysql/mysql-server --character-set-server=utf8 --collation-server=utf8_general_ci
-
修改navicat连接
docker exec -it mysql01 bash
mysql -uroot -ppwd123456 use mysql; # navicat连接mysql报错1251解决方案 ALTER USER 'jeese'@'%' IDENTIFIED WITH mysql_native_password BY 'pwd123456'; ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'pwd123456'; # 刷新 FLUSH PRIVILEGES;
- mysql挂载资料卷
#注意:需要先创建/docker/mysql/config/my.cnf文件和/docker/mysql/data文件夹 cd / mkdir docker cd docker mkdir mysql cd mysql mkdir config mkdir data vim config/my.cnf [mysqld] user=mysql character-set-server=utf8 [client] default-character-set=utf8 [mysql] default-character-set=utf8 # mysql挂载资料卷 docker run -d -p 3306:3306 -v /docker/mysql/config/my.cnf:/etc/my.cnf -v /docker/mysql/data:/var/lib/mysql -e MYSQL_USER="jeese" -e MYSQL_PASSWORD="pwd123456" -e MYSQL_ROOT_PASSWORD="pwd123456" -e MYSQL_ROOT_HOST=% --restart=always --name mysql01 mysql/mysql-server --character-set-server=utf8 --collation-server=utf8_general_ci
-
修改navicat连接
docker exec -it mysql01 bash
mysql -uroot -ppwd123456 use mysql; # navicat连接mysql报错1251解决方案 ALTER USER 'jeese'@'%' IDENTIFIED WITH mysql_native_password BY 'pwd123456'; ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'pwd123456'; # 刷新 FLUSH PRIVILEGES;
cd /docker/ mkdir mongo cd mongo mkdir config mkdir db docker run -d -p 27017:27017 --name mongo01 -v /docker/mongo/config:/data/configdb -v /docker/mongo/db:/data/db --restart=always mongo
作者:一个大西瓜
-------------------------------------------
个性签名:独学而无友,则孤陋而寡闻。做一个灵魂有趣的人!
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!
万水千山总是情,打赏一分行不行,所以如果你心情还比较高兴,也是可以扫码打赏博主,哈哈哈(っ•̀ω•́)っ✎⁾⁾!