欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

CentOS MySQL 5.7编译安装步骤详细说明

程序员文章站 2022-06-07 19:18:05
centos mysql 5.7编译安装 mysql 5.7 ga版本的发布,也就是说从现在开始5.7已经可以在生产环境中使用,有任何问题官方都将立刻修复。 mys...

centos mysql 5.7编译安装

mysql 5.7 ga版本的发布,也就是说从现在开始5.7已经可以在生产环境中使用,有任何问题官方都将立刻修复。

mysql 5.7主要特性:

  • 更好的性能:对于多核cpu、固态硬盘、锁有着更好的优化,每秒100w qps已不再是mysql的追求,下个版本能否上200w qps才是吾等用户更关心的
  • 更好的innodb存储引擎
  • 更为健壮的复制功能:复制带来了数据完全不丢失的方案,传统金融客户也可以选择使用mysql数据库。此外,gtid在线平滑升级也变得可能
  • 更好的优化器:优化器代码重构的意义将在这个版本及以后的版本中带来巨大的改进,oracle官方正在解决mysql之前最大的难题
  • 原生json类型的支持
  • 更好的地理信息服务支持:innodb原生支持地理位置类型,支持geojson,geohash特性
  • 新增sys库:以后这会是dba访问最频繁的库

mysql 5.7已经作为数据库可选项添加到《oneinstack》

安装依赖包

yum -y install gcc gcc-c++ ncurses ncurses-devel cmake

下载相应源码包

cd /root/oneinstack/src
wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
wget http://cdn.mysql.com/downloads/mysql-5.7/mysql-5.7.11.tar.gz

添加mysql用户

useradd -m -s /sbin/nologin mysql

预编译

tar xzf boost_1_59_0.tar.gz
tar xzf mysql-5.7.11.tar.gz
mkdir -p /data/mysql
cd mysql-5.7.11
cmake . -dcmake_install_prefix=/usr/local/mysql \
-dmysql_datadir=/data/mysql \
-ddownload_boost=1 \  #从mysql 5.7.5开始boost库是必需的
-dwith_boost=../boost_1_59_0 \
-dsysconfdir=/etc \
-dwith_innobase_storage_engine=1 \
-dwith_partition_storage_engine=1 \
-dwith_federated_storage_engine=1 \
-dwith_blackhole_storage_engine=1 \
-dwith_myisam_storage_engine=1 \
-denabled_local_infile=1 \
-denable_dtrace=0 \
-ddefault_charset=utf8mb4 \
-ddefault_collation=utf8mb4_general_ci \
-dwith_embedded_server=1

编译安装

make -j `grep processor /proc/cpuinfo | wc -l` #编译很消耗系统资源,小内存可能编译通不过
make install

启动脚本,设置开机自启动

/bin/cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on

/etc/my.cnf,仅供参考

cat > /etc/my.cnf << eof
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4
[mysqld]
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /data/mysql
pid-file = /data/mysql/mysql.pid
user = mysql
bind-address = 0.0.0.0
server-id = 1
init-connect = 'set names utf8mb4'
character-set-server = utf8mb4
#skip-name-resolve
#skip-networking
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4m
binlog_cache_size = 1m
max_heap_table_size = 8m
tmp_table_size = 16m
read_buffer_size = 2m
read_rnd_buffer_size = 8m
sort_buffer_size = 8m
join_buffer_size = 8m
key_buffer_size = 4m
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8m
query_cache_limit = 2m
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30
log_error = /data/mysql/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysql/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
#lower_case_table_names = 1
skip-external-locking
default_storage_engine = innodb
#default-storage-engine = myisam
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64m
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2m
innodb_log_file_size = 32m
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8m
myisam_sort_buffer_size = 8m
myisam_max_sort_file_size = 10g
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 16m
[myisamchk]
key_buffer_size = 8m
sort_buffer_size = 8m
read_buffer = 4m
write_buffer = 4m
eof

初始化数据库

注:

  • 之前版本mysql_install_db是在mysql_basedir/script下,5.7放在了mysql_install_db/bin目录下,且已被废弃
  • "--initialize"会生成一个随机密码(~/.mysql_secret),而"--initialize-insecure"不会生成密码
  • --datadir目标目录下不能有数据文件

启动数据库

/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql

设置数据库密码

dbrootpwd=oneinstack #数据库root密码
/usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'127.0.0.1' identified by \"$dbrootpwd\" with grant option;"
/usr/local/mysql/bin/mysql -e "grant all privileges on *.* to root@'localhost' identified by \"$dbrootpwd\" with grant option;"

 

 感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!