Linux系统快速安装MySQL5.7数据库笔记

2023年 7月 22日 34.2k 0

1、环境说明

环境:CentOS Linux release 7.9.2009 (Core)

MySQL版本:mysql-community-server-5.7.42-1.el7.x86_64

2、 环境准备

配置yum源:

# aliyun
$ mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
$ wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
$ sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
# 引自阿里云CentOS 镜像
# 腾讯云
$ wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo

$ yum clean all
$ yum makecache

下载和配置mysql5.7的yum源。

# 下载mysql源
$ wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

# 安装
$ yum localinstall mysql57-community-release-el7-8.noarch.rpm

# 查看源是否生效
$ yum repolist enabled | grep "mysql.*-community.*"

# 安装校验key
$ rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

查看MySQL的源:
image.png

3、安装数据库

添加mysql用户

$ useradd -M -s /sbin/nologin mysql
# yum安装数据库
$ yum install mysql-community-server -y

查看安装的数据库包:

image.png

4、配置数据库

编辑mysql配置文件

# 编辑my.cnf
$ cp /etc/my.cnf /etc/my.cnf.bak
$ vim /etc/my.cnf 

[mysqld]
user=mysql
port=3306
# 数据库数据目录
datadir=/opt/workspaces/mysql-server/data/
# 默认
socket=/var/lib/mysql/mysql.sock
pid-file=/var/run/mysqld/mysqld.pid
# 日志目录
log-error=/opt/workspaces/mysql-server/logs/mysqld.log
# 字符设置
character_set_server=utf8mb4
collation_server=utf8mb4_general_ci
# 数据库默认引擎
default_storage_engine=innodb
default_tmp_storage_engine=innodb
# transaction_isolation=READ-COMMITTED
# log_timestamps=system
skip_name_resolve=1
# lower_case_table_names=0#0表示区分大小写,1表示不区分大小写
# max_allowed_packet=32M
# back_log=1024
 thread_stack=512K
# bulk_insert_buffer_size=64M
 max_heap_table_size=32M
sql_mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER"
# max_connections=512
# max_connect_errors=1000000
# open_files_limit=65535
explicit_defaults_for_timestamp=1
#
# interactive_timeout=1800
# wait_timeout=1800
# lock_wait_timeout=1800
#
# table_open_cache=4000
# table_definition_cache=2000
# table_open_cache_instances=32
#
# read_buffer_size=8M
# read_rnd_buffer_size=4M
# sort_buffer_size=16M
# tmp_table_size=96M
# join_buffer_size=16M
# thread_cache_size=64
# key_buffer_size=32M
# myisam_sort_buffer_size=32M

# slowlog
slow_query_log=1
slow_query_log_file=/opt/workspaces/mysql-server/logs/slow.log
log_queries_not_using_indexes=1
log_slow_admin_statements=1
log_slow_slave_statements=1
log_throttle_queries_not_using_indexes=10
long_query_time=5

#binlogsettings
server-id=1
log_bin=/opt/workspaces/mysql-server/mysql-bin/mybinlog
log_error_verbosity=2
log_error_verbosity=2
binlog_cache_size=2M
max_binlog_size=1G
binlog_checksum=NONE
binlog_format=ROW
binlog_rows_query_log_events=1
# sync_binlog=1
expire_logs_days=7

log_timestamps=SYSTEM

配置内容参考如上,根据实际设置具体参数。

5、启动数据库

使用systemctl管理数据库

# 启动数据库
$ systemctl start mysqld
# 查看数据库状态
$ systemctl status mysqld
# 停止数据库
$ systemctl stop mysqld
# 开机自启动
$ systemctl enable mysqld

数据库启动后科进行初始化操作,通过

$ 

# 默认密码查看日志
$ cat logs/mysqld.log | grep password
$ cat /var/log/messages | grep password

参考文件:

阿里云CentOS 镜像:developer.aliyun.com/mirror/cent…

腾讯云yum源:mirrors.cloud.tencent.com/help/centos…

相关文章

服务器端口转发,带你了解服务器端口转发
服务器开放端口,服务器开放端口的步骤
产品推荐:7月受欢迎AI容器镜像来了,有Qwen系列大模型镜像
如何使用 WinGet 下载 Microsoft Store 应用
百度搜索:蓝易云 – 熟悉ubuntu apt-get命令详解
百度搜索:蓝易云 – 域名解析成功但ping不通解决方案

发布评论