我们自己在linux上安装MySQL的话,超级麻烦,安装完后还要进行各种各样的配置,之前在Docker专题写了用docker安装mysql的快速版本以及修改编码的方式,这里总结一下安装流程和命令。
下面我直接快速的说明安装流程和命令,包括中文编码问题的解决。
docker pull mysql:5.7
mkdir -p /data/mysql/data3309
mkdir -p /data/mysql/mysql.conf.d3309
这里启动的容器端口为3309,所以直接命名为3309
新建名称为mysqld.cnf的配置文件,访入/data/mysql/mysql.conf.d3309/目录下,内容如下,目的是覆盖掉容器内的配置文件,好修改编码格式为utf_8,而不是参照网上的进入容器中修改。
# 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
#innodb_buffer_pool_size = 50M
#ngram_token_size=1
#ft_min_word_len=3
#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
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
顺便说下,里面的这些配置,其实跟mysql的快速安装没有关系。主要是加上设置编码的内容,就是后面两句
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
innodb_buffer_pool_size默认是128Mngram_token_size默认分词是2,用于全文索引中文分词ft_min_word_len默认值是4,只有四个字母的单词才会建立全文索引
这里创建的容器端口为3309,root密码为123456,数据和配置文件挂载点用上面创建的目录,设置编码格式为utf8mb4
docker create --name mysql3308 -v /data/mysql/data3309:/var/lib/mysql -v /data/mysql/mysql.conf.d3309/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf -e MYSQL_ROOT_PASSWORD=123456 -p 3309:3306 mysql:5.7 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
docker start mysql3309
首先进入到容器
docker exec -it mysql3309 bash
然后用如下命令登录,当然也可以省去-h127.0.0.1
mysql -h127.0.0.1 -uroot -p123456
若是进入到mysql命令行界面就表明安装成功
只需要新建挂载点然后执行创建mysql容器命令即可。(注意端口号的修改)
docker stop mysql3309 #停止容器
docker start mysql3309 #启动容器
docker exec -it mysql3309 bash #进入容器
docker search name #查询镜像
docker pull name #安装name镜像
docker images #查看已经拉取的镜像
docker ps #查看正在运行中的容器
docker ps -a #查看正在运行中的容器,包括未运行的
docker rm #容器ID 删除某一容器 //停止容器--》删除容器--》删除镜像
docker rmi #镜像ID 删除某一个镜像
systemctl start docker #启动docker
systemctl stop docker #停止docker
systemctl restart docker #重启docker