前言:本文介绍 MySQL-5.7.26 编译和 Docker 安装方式;
什么是 MySQL?
MySQL 是一种开放源代码的关系型数据库管理系统,是世界上最受欢迎的开源数据库。凭借其可靠的性能,可靠性和易用性,MySQL 已成为基于 Web 的应用程序的领先数据库选择,涵盖了从个人项目和网站到电子商务和信息服务的所有范围,一直到备受关注网站属性,包括 Facebook,Twitter,YouTube,Yahoo!还有很多。
有关 MySQL 服务器和其他 MySQL 产品的更多信息和相关下载,请访问 www.mysql.com。
一、编译安装部分
- 安装依赖
For Ubuntu 16.04
sudo apt install make cmake gcc g++ perl bison libaio-dev libncurses5 libncurses5-dev libnuma-dev
For CentOS 7.6
sudo yum install gcc gcc-c++ pcre pcre-devel openssl openssl-devel zlib zlib-devel cmake ncurses ncurses-devel bison bison-devel
## 如下的几个依赖在CentOS7中需要安装,CentOS6不需要
sudo yum install perl perl-devel autoconf
## MySQL启动时创建目录否则会报错
mkdir /var/log/mariadb/
touch /var/log/mariadb/mariadb.log
chown -R mysql.mysql /var/log/mariadb/
Docker 方式快速启动 MySQL 实例:
docker run -d --restart=always --name mysql \
-e MYSQL_ROOT_PASSWORD=${ROOT_PASSWORD} \
-e MYSQL_DATABASE=${DB} \
-e MYSQL_USER=s${USER} \
-e MYSQL_PASSWORD=${USER_PASSWORD} \
-v ${PWD}/conf.d:/etc/mysql/conf.d \
-v ${PWD}/data:/var/lib/mysql \
mysql:5.7.28
- 源码获取
选项:
Source Code
-->Generic Linux (Architecture Independent)
-->mysql-5.7.26.tar.gz
执行 cmake .检测 mysql 的安装环境条件,升级 boost_1_59_0:
mkdir /usr/local/src/mysql_server && \
cd /usr/local/src/mysql_server && \
wget https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz && \
tar xzvf boost_1_59_0.tar.gz && \
cd boost_1_59_0 && \
./bootstrap.sh && \
./b2 install
- 编译安装
执行 cmake
cmake . -DBUILD_CONFIG=mysql_release \
-DCPACK_MONOLITHIC_INSTALL=ON \
-DCMAKE_INSTALL_PREFIX=/data/service/mysql5726 \
-DMYSQL_UNIX_ADDR=/data/service/mysql5726/log/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_DATADIR=/data/service/mysql5726/data \
-DSYSCONFDIR=/data/service/mysql5726/etc \
-DENABLE_DOWNLOADS=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=ON \
-DWITH_ARCHIVE_STORAGE_ENGINE=ON \
-DWITH_BLACKHOLE_STORAGE_ENGINE=ON \
-DWITH_BOOST=system
执行安装
make && make install
创建组和用户
groupadd mysql && useradd -r -g mysql -s /bin/false mysql
创建所需目录并更改权限
mkdir -pv /data/service/mysql5726/{data,log,etc,tmp}
chown -R mysql.mysql /data/service/mysql5726
创建 my.cnf
配置文件
cat << "EOF" >/data/service/mysql5726/etc/my.cnf
[mysqld]
skip-name-resolve
character_set_server=utf8
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#
# Basic Set
#
basedir = /data/service/mysql5726
datadir = /data/service/mysql5726/data
user = mysql
port = 3306
socket = /data/service/mysql5726/log/mysql.sock
pid-file = /data/service/mysql5726/log/mysql.pid
tmpdir = /data/service/mysql5726/tmp
#
# Connection Set
#
back_log = 200
max_connections = 1000
max_connect_errors = 100
interactive_timeout = 1800
wait_timeout = 1800
table_open_cache = 256
#
# Session Memory Set
#
read_buffer_size = 4M
read_rnd_buffer_size = 8M
tmp_table_size = 64M
join_buffer_size = 8M
thread_cache_size = 32
#
# Log settings #
#
log_error = /data/service/mysql5726/log/mysql_error.log
log_warnings = 1
slow_query_log = 1
slow_query_log_file = /data/service/mysql5726/log/mysql_slow.log
expire_logs_days = 1
long_query_time = 10
log-bin=mysql-bin
binlog-format=ROW
server-id=1
#
# innodb settings
#
innodb_data_file_path = ibdata1:10M:autoextend
innodb_lock_wait_timeout = 120
innodb_flush_method = O_DIRECT
innodb_buffer_pool_size = 2048M
innodb_log_file_size = 128M
innodb_log_files_in_group = 3
innodb_file_per_table = on
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 4M
innodb_thread_concurrency = 8
innodb_max_dirty_pages_pct = 90
key_buffer_size = 128M
max_heap_table_size = 32M
[mysqldump]
quick
max_allowed_packet = 32M
socket = /data/service/mysql5726/log/mysql.sock
[mysql]
prompt = [\u@\h:\p][\d]>\_
no-auto-rehash
default-character-set=utf8
safe-updates
[myisamchk]
key_buffer = 16M
sort_buffer_size = 16M
read_buffer = 8M
write_buffer = 8M
[mysqld_safe]
open-files-limit = 5000
[client]
default-character-set=utf8
socket = /data/service/mysql5726/log/mysql.sock
EOF
再次修改权限
chown -R mysql.mysql /data/service/mysql5726
初始化密码
#./bin/mysqld --initialize --user=mysql --basedir=/data/service/mysql5726 --defaults-file=/data/service/mysql5726/etc/my.cnf
bin/mysqld --initialize --user=mysql
根据报错排错,记录日志输出的密码
tailf /data/service/mysql5726/log/mysql_error.log
开启 SSL 功能
bin/mysql_ssl_rsa_setup
## 再次修改权限
chown -R mysql.mysql /data/service/mysql5726
测试启动 MySQL(可选)
bin/mysqld_safe --user=mysql
启动 mysql,输入临时密码后更改默认密码
cp support-files/mysql.server /etc/init.d/mysql.server
chmod +x /etc/init.d/mysql.server
systemctl enable mysql.server
systemctl start mysql.server
sudo bin/mysql -u root -p
alter user 'root'@'localhost' identified by 'aukeys@2019.com';
- 服务生命周期:
service mysql start|stop|restart|reload|force-reload|status
- 查看 MySQL 全局配置:
show global variables like '%log_bin%';
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于