k8s记录-docker源码安装mysql5.7.20
Posted 信方互联网硬汉
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了k8s记录-docker源码安装mysql5.7.20相关的知识,希望对你有一定的参考价值。
1.下载mysql源码
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.20.tar.gz
2.新建my.cnf文件
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1
3.新建dockerfile文件
FROM centos:7
ADD mysql-boost-5.7.20.tar.gz /opt
WORKDIR /opt/mysql-5.7.20/
RUN yum -y update
RUN yum -y install cmake ncurses ncurses-devel bison gcc gcc-c++ make
RUN useradd -s /sbin/nologin mysql
RUN cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DSYSCONFDIR=/etc/ -DSYSTEMD_PID_DIR=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/usr/local/mysql/data -DWITH_BOOST=boost -DWITH_SYSTEMD=1
RUN make && make install
RUN chown -R mysql:mysql /usr/local/mysql/
RUN rm -rf /etc/my.cnf
ADD my.cnf /etc
ENV PATH /usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
WORKDIR /usr/local/mysql
RUN bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
RUN cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
EXPOSE 3306
RUN echo -e "#!/bin/sh
systemctl enable mysqld" > /run.sh
RUN chmod 755 /run.sh
RUN sh /run.sh
CMD ["init"]
4.执行
build:docker build -t centos:mysql .
运行:docker run --name=mysql_server -d -P --privileged mysql:centos
进入容器:docker exec -it 容器id /bin/bash
修改密码:
mysql -u root -p
Enter password: #此处直接回车
grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘abc123‘;
grant all privileges on *.* to ‘root‘@‘localhost‘ identified by ‘abc123‘;
flush privileges
exit
以上是关于k8s记录-docker源码安装mysql5.7.20的主要内容,如果未能解决你的问题,请参考以下文章