Centos7下快速安装mysql5.7

Posted feko大魔王

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos7下快速安装mysql5.7相关的知识,希望对你有一定的参考价值。

安装mysql5.7

1.提前准备

yum install gcc mysql-libs mysql-devel -y
useradd mysql -s /sbin/nologin -M
if [ -f /etc/my.cnf ];then
/bin/mv /etc/my.cnf /etc/my.cnf.bak
fi
mkdir /data/soft/mysql -p ##mysql程序目录
mkdir /data/db/mysql -p ##mysql数据目录
mkdir /tmp/mysql ##mysql socket文件目录
mkdir /data/db/mysql/binlog ##mysql binlog目录
chown -R mysql.mysql /data/soft/mysql
chown -R mysql.mysql /data/db/mysql
chown -R mysql.mysql /tmp/mysql

2.下载二进制包

wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
## 或者网盘下载 链接: https://caiyun.139.com/m/i?185CDQsUyy6B5 提取码:uRG0
tar zxf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.36-linux-glibc2.12-x86_64/* /data/soft/mysql/

3.配置my.cnf文件

cat > /data/soft/mysql/my.cnf  <<EOF
[mysql]
default-character-set=utf8
host = localhost
socket=/tmp/mysql/mysql.sock
[mysqld]
user = mysql
bind-address = 0.0.0.0
socket=/tmp/mysql/mysql.sock
basedir=/data/soft/mysql
datadir=/data/db/mysql/data
log-bin=/data/db/mysql/binlog/binlog
expire_logs_days = 2
server-id=1
#skip-name-resolve
max_connections=4000
default_storage_engine = InnoDB
character_set_server = utf8
# INNODB OPTIONS #
innodb_buffer_pool_size = 2G
innodb_log_file_size = 256M
innodb_log_buffer_size = 32M
innodb_flush_log_at_trx_commit = 2
innodb_file_per_table = 1
innodb_open_files = 2048
# CACHES AND LIMITS #
tmp_table_size = 256M
max_heap_table_size = 256M
query_cache_type = 0
query_cache_size = 0
thread_cache_size = 32
open_files_limit = 65535
table_definition_cache = 4096
table_open_cache = 2048
interactive_timeout = 31536000
wait_timeout = 31536000
# MyISAM #
key_buffer_size = 32M
#myisam_recover = FORCE,BACKUP
# SAFETY #
max_allowed_packet = 1024M
max_connect_errors = 10000
sql_mode = NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
innodb = FORCE
[mysqldump]
quick
max_allowed_packet = 1024M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 128M
read_buffer = 4M
write_buffer = 4M
[mysqlhotcopy]
interactive-timeout
EOF

4.配置启动脚本

/bin/cp   /data/soft/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
sed -i "s#conf=/etc/my.cnf#conf=/data/soft/mysql/my.cnf#g" /etc/rc.d/init.d/mysqld
sed -i "s#conf=/etc/my.cnf#conf=/data/soft/mysql/my.cnf#g" /etc/rc.d/init.d/mysqld
sed -i "s#datadir=/usr/local/mysql/data#datadir=/data/db/mysql#g" /etc/rc.d/init.d/mysqld
sed -i "s#/usr/local/mysql#/data/soft/mysql#g" /etc/rc.d/init.d/mysqld

5.初始化mysql

/data/soft/mysql/bin/mysqld --defaults-file=/data/soft/mysql/my.cnf --user=mysql --basedir=/data/soft/mysql/  --initialize-insecure  ##初始化mysql
chmod +x /etc/init.d/mysqld
chkconfig mysqld on
chkconfig --add mysqld
/etc/init.d/mysqld start ##启动mysql
mkdir -p /var/lib/mysql
ln -sf /tmp/mysql/mysql.sock /tmp/mysql.sock
ln -s /tmp/mysql/mysql.sock /var/lib/mysql/mysql.sock
echo export PATH="$PATH:/data/soft/mysql/bin" >> /etc/profile
source /etc/profile

6.初始化root密码

mysqladmin  -uroot  password  123456  ##初始化root密码

以上是关于Centos7下快速安装mysql5.7的主要内容,如果未能解决你的问题,请参考以下文章

centos7快速安装mysql5.7

centos7.3 使用yum快速安装mysql5.7

速看!centos7下源码安装mysql5.7

CentOS7下安装MySQL5.7安装与配置

CentOS7下安装MySQL5.7安装与配置(YUM)

Centos7.4 版本环境下安装Mysql5.7操作记录