1、环境准备
虚拟机:centos 7 ip:192.168.137.128
mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz https://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
2、开始安装
添加mysql用户
useradd mysql -s /sbin/nologin
解压mysql二进制包并重命名
tar -zxf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.31-linux-glibc2.12-x86_64 mysql
新建mysql 数据存储目录data,以及创建my.cnf配置文件
my.cnf配置文件参考
[mysql]
port=3306
socket=/usr/local/mysql/mysql.sock
default-character-set=utf8
[mysqld_safe]
log-error=/usr/local/mysql/data/mysql.error
[mysqld]
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/mysql.sock
pid-file=/usr/local/mysql/mysql.pid
character-set-server=utf8
skip-name-resolve
lower_case_table_names=1
query_cache_size=0
transaction_isolation=READ-COMMITTED
tmp_table_size=128M
max_heap_table_size=96M
max_connections=1000
max_connect_errors=6000
long_query_time=1
innodb_buffer_pool_size=2G
innodb_flush_log_at_trx_commit=0
innodb_log_buffer_size=8M
innodb_log_file_size=128M
innodb_log_files_in_group=2
innodb_file_per_table=1
innodb_flush_method=O_DIRECT
innodb_file_format=Barracuda
innodb_write_io_threads=8
innodb_read_io_threads=4
innodb_doublewrite=0
innodb_purge_threads=1
innodb_stats_on_metadata=OFF
innodb_io_capacity=1000
log-bin-trust-function-creators=1
event_scheduler=on
初始化数据库
修改mysql目录的属主和属组
chown mysql:mysql mysql -R
初始化数据库
/usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/my.cnf --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
记录mysql初始化临时密码
修改mysql目录下support-files目录中的mysql.server文件
修改basedir和datadir
启动mysql服务
./mysql.server start
使用mysql临时随机密码登录数据库修改root密码,密码为强制修改,否则无法正常使用
./mysql -S/usr/local/mysql/mysql.sock -uroot -p
修改密码
ALTER USER USER() IDENTIFIED BY ‘密码‘;
flush privileges; # 刷新mysql表授权
到此,mysql二进制安装完成!