配置yum mysql5.7安装源
yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
配置mysql5.7安装源成功
查看配置成功的安装源
yum repolist enabled | grep "mysql*"
开始安装mysql5.7
yum install -y mysql-community-server
安装过程中止报错:Failing package is: mysql-community-server-5.7.44-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql,如下图:
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
安装完gpg-key后会生成一个文件:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql ,如下图:
安装gpg-key后再次安装mysql5.7,直到安装完成,如下图:
启动mysql
配置开机启动
systemctl enable mysqld
1 查看安装时生成的账户密码
grep 'temporary password' /var/log/mysqld.log
2 本地登陆mysql
mysql -uroot -p
首次登陆mysql必须先修改密码:
alter user root@localhost identified by 'xXx@123abc';
默认只允许本地访问,修改成远程访问:
update user set host='%' where user='root';
flush privileges;
测试远程访问成功,如下图:
mysql默认配置文件路径 /etc/my.cnf,可以针对需要进行配置,也可以使用默认配置。
mysql /etc/my.cnf 配置文件文本:
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/opt/mysql57
socket=/opt/mysql57/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
character-set-server=utf8mb4
back_log=600
max_connections=9000
max_connect_errors=6000
max_allowed_packet=128M
thread_cache_size=300
query_cache_type=1
query_cache_size=1024M
query_cache_limit=64M
default-time-zone='+08:00'
table_open_cache=800
slow_query_log=ON
slow_query_log_file=/var/log/slow_query.log
long_query_time=1
max_heap_table_size = 1024M
tmp_table_size = 1024M
transaction_isolation=READ-COMMITTED
innodb_buffer_pool_size = 2G
innodb_buffer_pool_chunk_size = 128M
innodb_buffer_pool_instances = 16
以下是对每个配置项目的简要解释:
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
:
NO_ENGINE_SUBSTITUTION
: 如果指定的存储引擎不可用,不要替换为默认的存储引擎。STRICT_TRANS_TABLES
: 启用严格模式,拒绝插入不符合表定义的数据。character-set-server=utf8mb4
:
back_log=600
:
max_connections=9000
:
max_connect_errors=6000
:
max_allowed_packet=128M
:
thread_cache_size=300
:
query_cache_type=1
:
query_cache_size=1024M
:
query_cache_limit=64M
:
default-time-zone='+08:00'
:
table_open_cache=800
:
slow_query_log=ON
:
long_query_time
阈值的查询。slow_query_log_file=/var/log/slow_query.log
:
long_query_time=1
:
max_heap_table_size = 1024M
:
tmp_table_size = 1024M
:
transaction_isolation=READ-COMMITTED
:
innodb_buffer_pool_size = 2G
:
innodb_buffer_pool_chunk_size = 128M
:
innodb_buffer_pool_instances = 16
:
这些参数的值可能需要根据具体的应用和服务器硬件进行调整,以达到最佳性能和稳定性。