docker部署MYSQL5.7

具体操作如下:
1.先启动mysql,执行下面的脚本(可选配置:–network=host )

docker run <span class="token operator">-</span>d <span class="token operator">--</span>name mysql <span class="token operator">-</span>it <span class="token operator">--</span>restart<span class="token operator">=</span>always \ <span class="token operator">-</span>v <span class="token operator">/</span>root<span class="token operator">/</span>mysql<span class="token operator">/</span>data<span class="token operator">:</span><span class="token operator">/</span><span class="token keyword">var</span><span class="token operator">/</span>lib<span class="token operator">/</span>mysql \ <span class="token operator">-</span>p <span class="token number">3306</span><span class="token operator">:</span><span class="token number">3306</span> <span class="token operator">-</span>e MYSQL_ROOT_PASSWORD<span class="token operator">=</span><span class="token string">"123456"</span> \ <span class="token operator">-</span>e MYSQL_USER<span class="token operator">=</span><span class="token string">"admin"</span> <span class="token operator">-</span>e MYSQL_PASSWORD<span class="token operator">=</span><span class="token string">"Xx123456."</span> \ mysql<span class="token operator">:</span><span class="token number">5.7</span><span class="token number">.26</span> <span class="token operator">--</span>lower_case_table_names<span class="token operator">=</span><span class="token number">1</span> <span class="token operator">--</span>character<span class="token operator">-</span>set<span class="token operator">-</span>server<span class="token operator">=</span>utf8 <span class="token operator">--</span>collation<span class="token operator">-</span>server<span class="token operator">=</span>utf8_general_ci
docker run <span class="token operator">-</span>d <span class="token operator">--</span>name mysql <span class="token operator">-</span>it <span class="token operator">--</span>restart<span class="token operator">=</span>always \ <span class="token operator">-</span>v <span class="token operator">/</span>root<span class="token operator">/</span>mysql<span class="token operator">/</span>data<span class="token operator">:</span><span class="token operator">/</span><span class="token keyword">var</span><span class="token operator">/</span>lib<span class="token operator">/</span>mysql \ <span class="token operator">-</span>p <span class="token number">3306</span><span class="token operator">:</span><span class="token number">3306</span> <span class="token operator">-</span>e MYSQL_ROOT_PASSWORD<span class="token operator">=</span><span class="token string">"123456"</span> \ <span class="token operator">-</span>e MYSQL_USER<span class="token operator">=</span><span class="token string">"admin"</span> <span class="token operator">-</span>e MYSQL_PASSWORD<span class="token operator">=</span><span class="token string">"Xx123456."</span> \ mysql<span class="token operator">:</span><span class="token number">5.7</span><span class="token number">.26</span> <span class="token operator">--</span>lower_case_table_names<span class="token operator">=</span><span class="token number">1</span> <span class="token operator">--</span>character<span class="token operator">-</span>set<span class="token operator">-</span>server<span class="token operator">=</span>utf8 <span class="token operator">--</span>collation<span class="token operator">-</span>server<span class="token operator">=</span>utf8_general_ci 
docker run -d --name mysql -it --restart=always \ -v /root/mysql/data:/var/lib/mysql \ -p 3306:3306 -e MYSQL_ROOT_PASSWORD="123456" \ -e MYSQL_USER="admin" -e MYSQL_PASSWORD="Xx123456." \ mysql:5.7.26 --lower_case_table_names=1 --character-set-server=utf8 --collation-server=utf8_general_ci

2.把容器中的配置文件复制到宿主机,再修改配置

docker cp mysql<span class="token operator">:</span><span class="token operator">/</span>etc<span class="token operator">/</span>mysql<span class="token operator">/</span>mysql<span class="token punctuation">.</span>conf<span class="token punctuation">.</span>d<span class="token operator">/</span>mysqld<span class="token punctuation">.</span>cnf <span class="token operator">/</span>root<span class="token operator">/</span>mysql<span class="token operator">/</span>conf<span class="token operator">/</span>
docker cp mysql<span class="token operator">:</span><span class="token operator">/</span>etc<span class="token operator">/</span>mysql<span class="token operator">/</span>mysql<span class="token punctuation">.</span>conf<span class="token punctuation">.</span>d<span class="token operator">/</span>mysqld<span class="token punctuation">.</span>cnf <span class="token operator">/</span>root<span class="token operator">/</span>mysql<span class="token operator">/</span>conf<span class="token operator">/</span> 
docker cp mysql:/etc/mysql/mysql.conf.d/mysqld.cnf /root/mysql/conf/

然后修改mysqld.cnf,加入sql_mode配置
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

本地mysqld.cnf的内容如下:

# <span class="token class-name">Copyright</span> <span class="token punctuation">(</span>c<span class="token punctuation">)</span> <span class="token number">2014</span><span class="token punctuation">,</span> <span class="token number">2016</span><span class="token punctuation">,</span> <span class="token class-name">Oracle</span> and<span class="token operator">/</span>or its <span class="token class-name"><span class="token namespace">affiliates<span class="token punctuation">.</span></span> All</span> rights reserved<span class="token punctuation">.</span> # # <span class="token class-name">This</span> program is free software<span class="token punctuation">;</span> you can redistribute it and<span class="token operator">/</span>or modify # it under the terms of the GNU <span class="token class-name">General</span> <span class="token class-name">Public</span> <span class="token class-name">License</span> as published by # the <span class="token class-name">Free</span> <span class="token class-name">Software</span> <span class="token class-name">Foundation</span><span class="token punctuation">;</span> version <span class="token number">2</span> of the <span class="token class-name">License</span><span class="token punctuation">.</span> # # <span class="token class-name">This</span> program is distributed in the hope that it will be useful<span class="token punctuation">,</span> # but WITHOUT <span class="token class-name">ANY</span> WARRANTY<span class="token punctuation">;</span> without even the implied warranty of # MERCHANTABILITY or FITNESS FOR <span class="token class-name">A</span> PARTICULAR <span class="token class-name">PURPOSE<span class="token punctuation">.</span> See</span> the # GNU <span class="token class-name">General</span> <span class="token class-name">Public</span> <span class="token class-name">License</span> <span class="token keyword">for</span> more details<span class="token punctuation">.</span> # # <span class="token class-name">You</span> should have received a copy of the GNU <span class="token class-name">General</span> <span class="token class-name">Public</span> <span class="token class-name">License</span> # along <span class="token keyword">with</span> <span class="token keyword">this</span> program<span class="token punctuation">;</span> <span class="token keyword">if</span> not<span class="token punctuation">,</span> write <span class="token keyword">to</span> <span class="token namespace">the</span> <span class="token class-name">Free</span> <span class="token class-name">Software</span> # <span class="token class-name">Foundation</span><span class="token punctuation">,</span> <span class="token class-name">Inc</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">51</span> <span class="token class-name">Franklin</span> <span class="token class-name">St</span><span class="token punctuation">,</span> <span class="token class-name">Fifth</span> <span class="token class-name">Floor</span><span class="token punctuation">,</span> <span class="token class-name">Boston</span><span class="token punctuation">,</span> MA <span class="token number">02110</span><span class="token operator">-</span><span class="token number">1301</span> USA # # <span class="token class-name">The</span> <span class="token class-name">MySQL</span> <span class="token class-name">Server</span> configuration file<span class="token punctuation">.</span> # # <span class="token class-name">For</span> explanations see # http<span class="token operator">:</span><span class="token operator">/</span><span class="token operator">/</span>dev<span class="token punctuation">.</span>mysql<span class="token punctuation">.</span>com<span class="token operator">/</span>doc<span class="token operator">/</span>mysql<span class="token operator">/</span>en<span class="token operator">/</span>server<span class="token operator">-</span>system<span class="token operator">-</span>variables<span class="token punctuation">.</span>html <span class="token punctuation">[</span>mysqld<span class="token punctuation">]</span> pid<span class="token operator">-</span>file <span class="token operator">=</span> <span class="token operator">/</span><span class="token keyword">var</span><span class="token operator">/</span>run<span class="token operator">/</span>mysqld<span class="token operator">/</span>mysqld<span class="token punctuation">.</span>pid socket <span class="token operator">=</span> <span class="token operator">/</span><span class="token keyword">var</span><span class="token operator">/</span>run<span class="token operator">/</span>mysqld<span class="token operator">/</span>mysqld<span class="token punctuation">.</span>sock datadir <span class="token operator">=</span> <span class="token operator">/</span><span class="token keyword">var</span><span class="token operator">/</span>lib<span class="token operator">/</span>mysql #log<span class="token operator">-</span>error <span class="token operator">=</span> <span class="token operator">/</span><span class="token keyword">var</span><span class="token operator">/</span>log<span class="token operator">/</span>mysql<span class="token operator">/</span>error<span class="token punctuation">.</span>log # <span class="token class-name">By</span> <span class="token keyword">default</span> we only accept connections from localhost #bind<span class="token operator">-</span>address <span class="token operator">=</span> <span class="token number">127.0</span><span class="token number">.0</span><span class="token number">.1</span> # <span class="token class-name">Disabling</span> symbolic<span class="token operator">-</span>links is recommended <span class="token keyword">to</span> <span class="token namespace">prevent</span> assorted security risks symbolic<span class="token operator">-</span>links<span class="token operator">=</span><span class="token number">0</span> #如果要更改docker mysql的端口,请先修改mysql<span class="token punctuation">.</span>cnf文件中的端口 port<span class="token operator">=</span><span class="token number">3306</span> #从 show variables like '<span class="token operator">%</span>sql_mode'<span class="token punctuation">;</span> 里面复制出来,并去掉了 only_full_group_by sql_mode<span class="token operator">=</span>STRICT_TRANS_TABLES<span class="token punctuation">,</span>NO_ZERO_IN_DATE<span class="token punctuation">,</span>NO_ZERO_DATE<span class="token punctuation">,</span>ERROR_FOR_DIVISION_BY_ZERO<span class="token punctuation">,</span>NO_AUTO_CREATE_USER<span class="token punctuation">,</span>NO_ENGINE_SUBSTITUTION
# <span class="token class-name">Copyright</span> <span class="token punctuation">(</span>c<span class="token punctuation">)</span> <span class="token number">2014</span><span class="token punctuation">,</span> <span class="token number">2016</span><span class="token punctuation">,</span> <span class="token class-name">Oracle</span> and<span class="token operator">/</span>or its <span class="token class-name"><span class="token namespace">affiliates<span class="token punctuation">.</span></span> All</span> rights reserved<span class="token punctuation">.</span> # # <span class="token class-name">This</span> program is free software<span class="token punctuation">;</span> you can redistribute it and<span class="token operator">/</span>or modify # it under the terms of the GNU <span class="token class-name">General</span> <span class="token class-name">Public</span> <span class="token class-name">License</span> as published by # the <span class="token class-name">Free</span> <span class="token class-name">Software</span> <span class="token class-name">Foundation</span><span class="token punctuation">;</span> version <span class="token number">2</span> of the <span class="token class-name">License</span><span class="token punctuation">.</span> # # <span class="token class-name">This</span> program is distributed in the hope that it will be useful<span class="token punctuation">,</span> # but WITHOUT <span class="token class-name">ANY</span> WARRANTY<span class="token punctuation">;</span> without even the implied warranty of # MERCHANTABILITY or FITNESS FOR <span class="token class-name">A</span> PARTICULAR <span class="token class-name">PURPOSE<span class="token punctuation">.</span> See</span> the # GNU <span class="token class-name">General</span> <span class="token class-name">Public</span> <span class="token class-name">License</span> <span class="token keyword">for</span> more details<span class="token punctuation">.</span> # # <span class="token class-name">You</span> should have received a copy of the GNU <span class="token class-name">General</span> <span class="token class-name">Public</span> <span class="token class-name">License</span> # along <span class="token keyword">with</span> <span class="token keyword">this</span> program<span class="token punctuation">;</span> <span class="token keyword">if</span> not<span class="token punctuation">,</span> write <span class="token keyword">to</span> <span class="token namespace">the</span> <span class="token class-name">Free</span> <span class="token class-name">Software</span> # <span class="token class-name">Foundation</span><span class="token punctuation">,</span> <span class="token class-name">Inc</span><span class="token punctuation">.</span><span class="token punctuation">,</span> <span class="token number">51</span> <span class="token class-name">Franklin</span> <span class="token class-name">St</span><span class="token punctuation">,</span> <span class="token class-name">Fifth</span> <span class="token class-name">Floor</span><span class="token punctuation">,</span> <span class="token class-name">Boston</span><span class="token punctuation">,</span> MA <span class="token number">02110</span><span class="token operator">-</span><span class="token number">1301</span> USA # # <span class="token class-name">The</span> <span class="token class-name">MySQL</span> <span class="token class-name">Server</span> configuration file<span class="token punctuation">.</span> # # <span class="token class-name">For</span> explanations see # http<span class="token operator">:</span><span class="token operator">/</span><span class="token operator">/</span>dev<span class="token punctuation">.</span>mysql<span class="token punctuation">.</span>com<span class="token operator">/</span>doc<span class="token operator">/</span>mysql<span class="token operator">/</span>en<span class="token operator">/</span>server<span class="token operator">-</span>system<span class="token operator">-</span>variables<span class="token punctuation">.</span>html <span class="token punctuation">[</span>mysqld<span class="token punctuation">]</span> pid<span class="token operator">-</span>file <span class="token operator">=</span> <span class="token operator">/</span><span class="token keyword">var</span><span class="token operator">/</span>run<span class="token operator">/</span>mysqld<span class="token operator">/</span>mysqld<span class="token punctuation">.</span>pid socket <span class="token operator">=</span> <span class="token operator">/</span><span class="token keyword">var</span><span class="token operator">/</span>run<span class="token operator">/</span>mysqld<span class="token operator">/</span>mysqld<span class="token punctuation">.</span>sock datadir <span class="token operator">=</span> <span class="token operator">/</span><span class="token keyword">var</span><span class="token operator">/</span>lib<span class="token operator">/</span>mysql #log<span class="token operator">-</span>error <span class="token operator">=</span> <span class="token operator">/</span><span class="token keyword">var</span><span class="token operator">/</span>log<span class="token operator">/</span>mysql<span class="token operator">/</span>error<span class="token punctuation">.</span>log # <span class="token class-name">By</span> <span class="token keyword">default</span> we only accept connections from localhost #bind<span class="token operator">-</span>address <span class="token operator">=</span> <span class="token number">127.0</span><span class="token number">.0</span><span class="token number">.1</span> # <span class="token class-name">Disabling</span> symbolic<span class="token operator">-</span>links is recommended <span class="token keyword">to</span> <span class="token namespace">prevent</span> assorted security risks symbolic<span class="token operator">-</span>links<span class="token operator">=</span><span class="token number">0</span> #如果要更改docker mysql的端口,请先修改mysql<span class="token punctuation">.</span>cnf文件中的端口 port<span class="token operator">=</span><span class="token number">3306</span> #从 show variables like '<span class="token operator">%</span>sql_mode'<span class="token punctuation">;</span> 里面复制出来,并去掉了 only_full_group_by sql_mode<span class="token operator">=</span>STRICT_TRANS_TABLES<span class="token punctuation">,</span>NO_ZERO_IN_DATE<span class="token punctuation">,</span>NO_ZERO_DATE<span class="token punctuation">,</span>ERROR_FOR_DIVISION_BY_ZERO<span class="token punctuation">,</span>NO_AUTO_CREATE_USER<span class="token punctuation">,</span>NO_ENGINE_SUBSTITUTION 
# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # # The MySQL Server configuration file. # # For explanations see # http://dev.mysql.com/doc/mysql/en/server-system-variables.html [mysqld] pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock datadir = /var/lib/mysql #log-error = /var/log/mysql/error.log # By default we only accept connections from localhost #bind-address = 127.0.0.1 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 #如果要更改docker mysql的端口,请先修改mysql.cnf文件中的端口 port=3306 #从 show variables like '%sql_mode'; 里面复制出来,并去掉了 only_full_group_by sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

docker mysql 更改端口,需要先改MySQL配置文件中的端口,再在docker 启动命令中 -p 3308:3308

3.定制mysql容器,且移除mysql容器,并使用本地的mysqld.cnf配置文件,脚本如下:

docker stop mysql<span class="token punctuation">;</span>docker rm mysql<span class="token punctuation">;</span>docker run <span class="token operator">-</span>d <span class="token operator">--</span>name mysql <span class="token operator">-</span>it <span class="token operator">--</span>restart<span class="token operator">=</span>always \ <span class="token operator">-</span>v <span class="token operator">/</span>home<span class="token operator">/</span>mysql<span class="token operator">/</span>data<span class="token operator">:</span><span class="token operator">/</span><span class="token keyword">var</span><span class="token operator">/</span>lib<span class="token operator">/</span>mysql \ <span class="token operator">-</span>v <span class="token operator">/</span>home<span class="token operator">/</span>mysql<span class="token operator">/</span>conf<span class="token operator">/</span>mysqld<span class="token punctuation">.</span>cnf<span class="token operator">:</span><span class="token operator">/</span>etc<span class="token operator">/</span>mysql<span class="token operator">/</span>mysql<span class="token punctuation">.</span>conf<span class="token punctuation">.</span>d<span class="token operator">/</span>mysqld<span class="token punctuation">.</span>cnf \ # <span class="token operator">-</span>v <span class="token operator">/</span>home<span class="token operator">/</span>mysql<span class="token operator">/</span>log<span class="token operator">:</span><span class="token operator">/</span><span class="token keyword">var</span><span class="token operator">/</span>log<span class="token operator">/</span>mysql \ <span class="token operator">-</span>p <span class="token number">3306</span><span class="token operator">:</span><span class="token number">3306</span> <span class="token operator">-</span>e MYSQL_ROOT_PASSWORD<span class="token operator">=</span><span class="token string">"123456"</span> \ <span class="token operator">-</span>e MYSQL_USER<span class="token operator">=</span><span class="token string">"admin"</span> <span class="token operator">-</span>e MYSQL_PASSWORD<span class="token operator">=</span><span class="token string">"Xx123456."</span> \ <span class="token operator">-</span>e TZ<span class="token operator">=</span><span class="token class-name">Asia</span><span class="token operator">/</span><span class="token class-name">Shanghai</span> \ mysql<span class="token operator">:</span><span class="token number">5.7</span><span class="token number">.26</span> <span class="token operator">--</span>lower_case_table_names<span class="token operator">=</span><span class="token number">1</span> <span class="token operator">--</span>character<span class="token operator">-</span>set<span class="token operator">-</span>server<span class="token operator">=</span>utf8 <span class="token operator">--</span>collation<span class="token operator">-</span>server<span class="token operator">=</span>utf8_general_ci
docker stop mysql<span class="token punctuation">;</span>docker rm mysql<span class="token punctuation">;</span>docker run <span class="token operator">-</span>d <span class="token operator">--</span>name mysql <span class="token operator">-</span>it <span class="token operator">--</span>restart<span class="token operator">=</span>always \ <span class="token operator">-</span>v <span class="token operator">/</span>home<span class="token operator">/</span>mysql<span class="token operator">/</span>data<span class="token operator">:</span><span class="token operator">/</span><span class="token keyword">var</span><span class="token operator">/</span>lib<span class="token operator">/</span>mysql \ <span class="token operator">-</span>v <span class="token operator">/</span>home<span class="token operator">/</span>mysql<span class="token operator">/</span>conf<span class="token operator">/</span>mysqld<span class="token punctuation">.</span>cnf<span class="token operator">:</span><span class="token operator">/</span>etc<span class="token operator">/</span>mysql<span class="token operator">/</span>mysql<span class="token punctuation">.</span>conf<span class="token punctuation">.</span>d<span class="token operator">/</span>mysqld<span class="token punctuation">.</span>cnf \ # <span class="token operator">-</span>v <span class="token operator">/</span>home<span class="token operator">/</span>mysql<span class="token operator">/</span>log<span class="token operator">:</span><span class="token operator">/</span><span class="token keyword">var</span><span class="token operator">/</span>log<span class="token operator">/</span>mysql \ <span class="token operator">-</span>p <span class="token number">3306</span><span class="token operator">:</span><span class="token number">3306</span> <span class="token operator">-</span>e MYSQL_ROOT_PASSWORD<span class="token operator">=</span><span class="token string">"123456"</span> \ <span class="token operator">-</span>e MYSQL_USER<span class="token operator">=</span><span class="token string">"admin"</span> <span class="token operator">-</span>e MYSQL_PASSWORD<span class="token operator">=</span><span class="token string">"Xx123456."</span> \ <span class="token operator">-</span>e TZ<span class="token operator">=</span><span class="token class-name">Asia</span><span class="token operator">/</span><span class="token class-name">Shanghai</span> \ mysql<span class="token operator">:</span><span class="token number">5.7</span><span class="token number">.26</span> <span class="token operator">--</span>lower_case_table_names<span class="token operator">=</span><span class="token number">1</span> <span class="token operator">--</span>character<span class="token operator">-</span>set<span class="token operator">-</span>server<span class="token operator">=</span>utf8 <span class="token operator">--</span>collation<span class="token operator">-</span>server<span class="token operator">=</span>utf8_general_ci 
docker stop mysql;docker rm mysql;docker run -d --name mysql -it --restart=always \ -v /home/mysql/data:/var/lib/mysql \ -v /home/mysql/conf/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf \ # -v /home/mysql/log:/var/log/mysql \ -p 3306:3306 -e MYSQL_ROOT_PASSWORD="123456" \ -e MYSQL_USER="admin" -e MYSQL_PASSWORD="Xx123456." \ -e TZ=Asia/Shanghai \ mysql:5.7.26 --lower_case_table_names=1 --character-set-server=utf8 --collation-server=utf8_general_ci

再次启动mysql,执行sql时没有 only_full_group_by 的问题了

如果要创建新用户,则进行如下操作:

# 1.进入mysql容器 docker exec -it mysql bash # 2.登录mysql的root mysql -uroot -p 输入root密码:123456 # 3.创建用户和赋权限 use mysql; # 3.1.创建一个新用户 testuser 密码为 testuserpass CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'testuserpass'; # 3.2.创建数据库testDB create database testDB; # 3.3.为testuser用户添加使用testDB权限 grant all privileges on testDB.* to testuser@localhost identified by 'testuserpass'; # 3.4.为testuser用户添加远程访问权限 GRANT ALL PRIVILEGES ON testDB.* TO 'testuser'@'%' IDENTIFIED BY 'testuserpass' WITH GRANT OPTION; # 3.5.刷新权限表,使命令生效 flush privileges; # 3.6.为用户添加所有数据库的权限 grant all on *.* to testuser@'%' identified by 'testuserpass';
# 1.进入mysql容器 docker exec -it mysql bash # 2.登录mysql的root mysql -uroot -p 输入root密码:123456 # 3.创建用户和赋权限 use mysql; # 3.1.创建一个新用户 testuser 密码为 testuserpass CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'testuserpass'; # 3.2.创建数据库testDB create database testDB; # 3.3.为testuser用户添加使用testDB权限 grant all privileges on testDB.* to testuser@localhost identified by 'testuserpass'; # 3.4.为testuser用户添加远程访问权限 GRANT ALL PRIVILEGES ON testDB.* TO 'testuser'@'%' IDENTIFIED BY 'testuserpass' WITH GRANT OPTION; # 3.5.刷新权限表,使命令生效 flush privileges; # 3.6.为用户添加所有数据库的权限 grant all on *.* to testuser@'%' identified by 'testuserpass'; 
# 1.进入mysql容器 docker exec -it mysql bash # 2.登录mysql的root mysql -uroot -p 输入root密码:123456 # 3.创建用户和赋权限 use mysql; # 3.1.创建一个新用户 testuser 密码为 testuserpass CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'testuserpass'; # 3.2.创建数据库testDB create database testDB; # 3.3.为testuser用户添加使用testDB权限 grant all privileges on testDB.* to testuser@localhost identified by 'testuserpass'; # 3.4.为testuser用户添加远程访问权限 GRANT ALL PRIVILEGES ON testDB.* TO 'testuser'@'%' IDENTIFIED BY 'testuserpass' WITH GRANT OPTION; # 3.5.刷新权限表,使命令生效 flush privileges; # 3.6.为用户添加所有数据库的权限 grant all on *.* to testuser@'%' identified by 'testuserpass';

原文链接:https://blog.csdn.net/zhuyu19911016520/article/details/104707595?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522171836884016800182130287%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=171836884016800182130287&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-29-104707595-null-null.nonecase&utm_term=docker%E9%83%A8%E7%BD%B2

© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享