一个80后
程序员的笔记

[Centos]mysql5.7编译安装

#下载地址:https://dev.mysql.com/downloads/mysql/
#工具包 https://gitee.com/bbhsky/MySQL-Setup.git
tar zxvf mysql-5.7.23.tar.gz
tar zxvf boost_1_68_0.tar.gz
cd mysql-5.7.23/
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql57 -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_BOOST=/root/src/MySQL-Setup/boost_1_59_0/
make && make install
groupadd mysql
useradd -s /sbin/nologin -M -g mysql mysql
ln -sf /usr/local/mysql57/ /usr/local/mysql
cp conf/mysql57-2048.cnf /etc/my.cnf #复制优化过的内存的配置文件
#或生成配置文件
cat > /etc/my.cnf<<EOF
[client]
#password   = your_password
port        = 3306
socket      = /tmp/mysql.sock
[mysqld]
port        = 3306
socket      = /tmp/mysql.sock
datadir = /usr/local/mysql/var
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
thread_cache_size = 8
query_cache_size = 8M
tmp_table_size = 16M
performance_schema_max_table_instances = 500
explicit_defaults_for_timestamp = true
#skip-networking
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
log-bin=mysql-bin
binlog_format=mixed
server-id   = 1
expire_logs_days = 10
early-plugin-load = ""
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_data_home_dir = /usr/local/mysql/var
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /usr/local/mysql/var
innodb_buffer_pool_size = 16M
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
${MySQLMAOpt}
EOF

#如果需要开启Innodb
sed -i 's/^#innodb/innodb/g' /etc/my.cnf
#如果不开启Innodb
sed -i '/^default_storage_engine/d' /etc/my.cnf
sed -i 's#default_storage_engine.*#default_storage_engine = MyISAM#' /etc/my.cnf

mkdir -p /home/mysql/var
ln -sf /home/mysql/var /usr/local/mysql/var
chown -R mysql:mysql /usr/local/mysql/var
chown -R mysql:mysql /home/mysql/var
/usr/local/mysql/bin/mysqld --initialize-insecure --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var --user=mysql
chgrp -R mysql /usr/local/mysql/.
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
chmod 755 /etc/init.d/mysql
cat > /etc/ld.so.conf.d/mysql.conf<<EOF
/usr/local/mysql/lib
/usr/local/lib
EOF
ldconfig
ln -sf /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -sf /usr/local/mysql/include/mysql /usr/include/mysql
systemctl enable mysql.service
/etc/init.d/mysql start
ln -sf /usr/local/mysql/bin/mysql /usr/bin/mysql
ln -sf /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump
ln -sf /usr/local/mysql/bin/myisamchk /usr/bin/myisamchk
ln -sf /usr/local/mysql/bin/mysqld_safe /usr/bin/mysqld_safe
ln -sf /usr/local/mysql/bin/mysqlcheck /usr/bin/mysqlcheck
/etc/init.d/mysql restart
/usr/local/mysql/bin/mysqladmin -u root password "password"
#优化数据库
mysql -uroot -p
mysql> DELETE FROM mysql.user WHERE User='';
mysql> DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');
mysql> DROP DATABASE test;
mysql> FLUSH PRIVILEGES;
/etc/init.d/mysql restart
赞(23) 打赏
未经允许不得转载:笨笨天地 » [Centos]mysql5.7编译安装
分享到: 更多 (0)

相关推荐

  • 暂无文章

评论 1

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏