docker部署mysql

1. docker部署 mysql

docker run --name mysql-demo -d \
-v /data/docker/mysql-demo/data:/var/lib/mysql \
-v /data/docker/mysql-demo/logs:/logs \
-v /data/docker/mysql-demo/conf:/etc/mysql/conf.d \
-e MYSQL_ROOT_PASSWORD=123456 \
-p '3306:3306' \
mysql:5.7.19 \
--character-set-server utf8 --collation-server utf8_general_ci

/data/docker/mysql-demo/conf 是本地存储mysql配置的目录, 如果需要新增 mysql的配置,需要将问价放在这个目录下面

需要注意的是:

文件必须是 *.cnf 的格式,否则识别不了

2. 添加配置文件

/data/docker/mysql-demo/conf 目录下创建文件 xx.cnf (可能需要root权限), 文件内容大致如下:

[mysqld]
tmp_table_size = 1024M
max_heap_table_size = 1024M

重启 mysql后,配置生效。 可以通过 show variables like '%tmp_table_size%' 来查看配置是否生效。

3. 查看mysql可用参数

进入容器内部: docker exec -it mysql-demo bash

查看默认文件: cat /etc/mysql/mysql.conf.d/mysqld.cnf , 内容如下:

# 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

打开这个页面 则能看到更详细的参数设置: https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html

results matching ""

    No results matching ""