CentOS7.9安装MySQL5.7

安装前说明:

开启安装模式

1、安装依赖包创建 mysql 用户

libaio 属于建议安装的系统包,该功能可以提高数据库的 IO 性能

系统自带的有 yum 源可以使用 yum 安装或者使用系统自带的镜像进行 RPM 安装

[root@localhost ~]# yum install libaio -y
#rpm 安装命令:
rpm -ivh libaio-0.3.107-10.el6.x86_64.rpm

2、 创建 mysql 用户和用户组

[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r -g mysql -s /bin/false mysql

3、上传并解压安装包(上传路径没有要求)

[root@localhost ~]# cp mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz  /usr/local/
[root@localhost local]# cd /usr/local/
[root@localhost local]# gzip -d mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz 
[root@localhost local]# tar xvf mysql-5.7.37-linux-glibc2.12-x86_64.tar
[root@localhost local]# mv /usr/local/mysql-5.7.37-linux-glibc2.12-x86_64 /usr/local/mysql
[root@localhost local]# cd mysql
[root@localhost mysql]# chown mysql:mysql -R /usr/local/mysql/*

4、初始化数据库,编辑 my.cnf 配置文件(仅供参考):

[root@localhost ~]# vi /etc/my.cnf
[mysqld]
user=mysql
port = 3306
socket = /var/lib/mysql/mysql.sock
datadir = /var/lib/mysql
character-set-server=utf8
server-id = 1
max_connections = 1000
group_concat_max_len = 102400
max_connect_errors = 10
table_open_cache = 4096
event_scheduler = ON
skip-name-resolve
lower_case_table_names = 1
max_allowed_packet = 64M
binlog_cache_size = 32M
max_heap_table_size = 256M
read_rnd_buffer_size = 64M
sort_buffer_size = 256M
join_buffer_size = 512M
thread_cache_size = 300
log_bin_trust_function_creators=1
key_buffer_size = 256M
read_buffer_size = 32M
read_rnd_buffer_size = 128M
bulk_insert_buffer_size = 512M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
######READ-UNCOMMITTED, READ-COMMITTED, REPEATABLE-READ, SERIALIZABLE
transaction_isolation = READ-COMMITTED
tmp_table_size = 512M
log-bin=mysql-bin
binlog_format=mixed
expire_logs_days = 15
slow_query_log = 1
slow_query_log_file = /var/lib/mysql/slow.log
long_query_time = 5
####### InnoDB
innodb_buffer_pool_size = 512M
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 32M
innodb_log_file_size = 1024M
innodb_log_files_in_group = 4
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
#innodb_force_recovery=1
[mysqldump]
quick
max_allowed_packet = 64M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer = 16M
sort_buffer_size = 16M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 65535
log-error=/var/lib/mysql/mysqld.log
pid-file=/var/lib/mysql/mysqld.pid

5、初始化数据库,安装加密算法,并启动数据库(初始化过程有随机的 root 密码,注意输出信息)

[root@localhost mysql]# cd /usr/local/mysql
[root@localhost mysql]# bin/mysqld --initialize --user=mysql
#注意此处的系统输出信息中包含系统默认的 root 用户密码,请记录下来。
2022-04-25T11:12:39.094657Z 1 [Note] A temporary password is generated for root@localhost: VjKzpY#-k8Rh

6、安装加密算法

[root@localhost mysql]# bin/mysql_ssl_rsa_setup

7、注册数据库服务

[root@localhost mysql]# cd /usr/local/mysql
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# chmod +x /etc/init.d/mysqld
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig mysqld on

8、启动 mysql 服务

[root@localhost mysql]#service mysqld star

9、配置数据库的 sock 文件,并修改 root 用户的初始密码

[root@localhost mysql]# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
[root@localhost mysql]# /usr/local/mysql/bin/mysql -uroot -p
Enter password: 输入随机生成的密码(即步骤 6 记录下来的密码)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.12
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> set password = 'mysqltest123';
Query OK, 0 rows affected (0.01 sec)

10、创建 ecology 数据库,并创建账号,赋权

mysql>create database finereport;
mysql> create user finereport identified with mysql_native_password by 'finereport;123';
mysql> grant all privileges on *.* to ' finereport '@'%';
mysql> flush privileges;

11、停止 mysql 服务

[root@localhost mysql]#service mysqld stop
THE END
分享
二维码
打赏
海报
CentOS7.9安装MySQL5.7
安装前说明: mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz CentOS-7-x86_64-DVD-2009.isoMysql 安装路径(以下目录不需提前创建)mysql 软件主目录:/usr……
<<上一篇
下一篇>>