1. 安装mysql
tar -xvf mysql-8.0.21-linux-glibc2.12-x86_64.tar
mv mysql-8.0.21-linux-glibc2.12-x86_64 /usr/local/mysql
2. 配置mysql
vim /etc/my.cnf
[client]
default-character-set=utf8mb4
[mysqld]
#nd-address=0.0.0.0
port=3306
user=mysql
basedir=/usr/local/mysql
datadir=/home/mysql/data
socket=/tmp/mysql.sock
log-error=/home/mysql/data/mysql.err
pid-file=/home/mysql/data/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
lower_case_table_names=1
#skip-grant-tables
#default-authentication-plugin=mysql_native_password
default-time_zone = '+8:00'
log_bin_trust_function_creators=1
join_buffer_size = 16M
#二进制日志目录
log-bin = /home/mysql/data/mysql-bin
#自动删除过期日志的天数
# expire_logs_days = 10
#限制单个文件大小
max_binlog_size = 100M
#查询日志
general_log = 1
#查询日志文件位置
general_log_file = /home/mysql/log/query.log
#慢查询日志
slow_query_log = 1
#慢日志文件位置
slow_query_log_file = /home/mysql/log/slow-query.log
#超过2秒记录
long_query_time = 2
#错误日志
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
back_log = 600
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
skip-name-resolve=ON
#innodb_dedicated_server=ON
#InnoDB#
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
innodb_buffer_pool_size=2G
#innodb_additional_pool_size=20M
innodb_log_file_size=256M
innodb_log_buffer_size=12M
innodb_flush_log_at_trx_commit=2
#innodb_flush_method
#thread_cache=8
#innodb_autoextend_increment=128M
log_bin_trust_function_creators=1
transaction-isolation = READ-COMMITTED
wait_timeout=7200
interactive_timeout=7200
net_read_timeout=600
net_write_timeout=600
#这里确认是否起用压缩存储功能
innodb_file_per_table=1
#innodb_file_format=barracuda #mysql 8 不支持该功能
#决定压缩程度的参数,如果你设置比较大,那么压缩比较多,耗费的CPU资源也较多;
#相反,如果设置较小的值,那么CPU占用少。默认值6,可以设置0-9#
innodb_compression_level=6
#指定在每个压缩页面可以作为空闲空间的最大比例,
#该参数仅仅应用在设置了innodb_compression_failure_threshold_pct不为零情况下,并且压缩失败率通过了中断点。
#默认值50,可以设置范围是0到75
innodb_compression_pad_pct_max=50
#default-character-set=utf8
init_connect='SET NAMES utf8mb4'
[mysql]
default-character-set = utf8mb4
mkdir -p /home/mysql/data
mkdir -p /home/mysql/log
3.创建mysql用户、组
groupadd mysql
useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/mysql
cd /usr/local/mysql
chown -R mysql .
chgrp -R mysql .
chown -R mysql /home/mysql/data
4.初始化mysql
cd /usr/local/mysql/bin/
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/home/mysql/data/ --user=mysql --initialize
5. 查看root初始密码
cd /home/mysql/data/
cat mysql.err
6. 设置软连接
ln -s /usr/local/mysql/bin/mysqldump /usr/bin
ln -s /usr/local/mysql/bin/mysql /usr/bin
7. libtinfo.so.5缺失处理
find / -name libtinfo.so.*
ln -s /usr/lib64/libtinfo.so.6.4 /usr/lib64/libtinfo.so.5
8. 设置service,并启动MYSQL
cd /usr/local/mysql
cp -a ./support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
service mysqld start
9. 登录mysql,初始密码参看步骤5
mysql -uroot -p
10. 改root密码
alter user user() identified by "新密码";
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
FLUSH PRIVILEGES;
use mysql
update user set host = '%' where user = 'root';
FLUSH PRIVILEGES;
11. 开启防火墙,远程测试
firewall-cmd --permanent --add-port=3306/tcp
firewall-cmd --reload
标签:log,MySQL8.241227,innodb,usr,mysql,home,OpenEuler,local,欧拉
From: https://www.cnblogs.com/amadeuslee/p/18650264