主要是试了一下rpm安装,Generic的安装参照另一篇文章
MySQL下载:https://dev.mysql.com/downloads/mysql/
centos死了,转redhat,反而觉得Generic的安装包更顺滑
开始:
1.安装包及安装环境
[root@localhost tmp]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.9 (Maipo)
[root@localhost tmp]# pwd
/tmp
[root@localhost tmp]# ll
total 2038628
-rw-r--r--. 1 root root 1043773440 Jun 26 15:20 mysql-8.0.37-1.el7.x86_64.rpm-bundle.tar
-rw-r--r--. 1 7155 31415 16768148 Mar 31 22:51 mysql-community-client-8.0.37-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 3621444 Mar 31 22:52 mysql-community-client-plugins-8.0.37-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 681816 Mar 31 22:52 mysql-community-common-8.0.37-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 538409072 Mar 31 22:53 mysql-community-debuginfo-8.0.37-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 1948516 Mar 31 22:53 mysql-community-devel-8.0.37-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 4218268 Mar 31 22:53 mysql-community-embedded-compat-8.0.37-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 2344724 Mar 31 22:53 mysql-community-icu-data-files-8.0.37-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 1564000 Mar 31 22:53 mysql-community-libs-8.0.37-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 685676 Mar 31 22:53 mysql-community-libs-compat-8.0.37-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 67951180 Mar 31 22:54 mysql-community-server-8.0.37-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 25689952 Mar 31 22:54 mysql-community-server-debug-8.0.37-1.el7.x86_64.rpm
-rw-r--r--. 1 7155 31415 379877568 Mar 31 22:56 mysql-community-test-8.0.37-1.el7.x86_64.rpm
需要先卸载mariadb,然后再安装,不然会报错,顺序记不得,慢慢试吧,一试一个不吱声
[root@localhost tmp]# rpm -qa|grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost tmp]# rpm -e mariadb-libs-5.5.68-1.el7.x86_64 --nodeps
[root@localhost tmp]# rpm -ivh mysql-community-libs-8.0.37-1.el7.x86_64.rpm
warning: mysql-community-libs-8.0.37-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-libs-8.0.37-1.el7################################# [100%]
[root@localhost tmp]#
[root@localhost tmp]# rpm -ivh mysql-community-client-8.0.37-1.el7.x86_64.rpm
warning: mysql-community-client-8.0.37-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-client-8.0.37-1.e################################# [100%]
[root@localhost tmp]# rpm -ivh mysql-community-server-8.0.37-1.el7.x86_64.rpm
warning: mysql-community-server-8.0.37-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-server-8.0.37-1.e################################# [100%]
rpm的方式 家目录默认是/usr即basedir=/usr
https://dev.mysql.com/doc/refman/8.0/en/binary-installation.html
#建立用户和组
#rpm安装不用手动建组/用户,上一步的几个包安装好之后,用户和组就自动建好了
[root@localhost mysql]# groupadd mysql
[root@localhost mysql]# useradd -r -g mysql -s /bin/false mysql
#创建相关目录
[root@localhost mysql]# mkdir -p /mysql/app
[root@localhost mysql]# mkdir -p /mysql/data
[root@localhost mysql]# mkdir -p /mysql/log
[root@localhost mysql]# mkdir -p /mysql/tmp
[root@localhost mysql]# chown -R mysql:mysql /mysql
[root@localhost mysql]# chmod 755 /mysql
[root@localhost mysql]#systemctl stop firewalld
[root@localhost mysql]#systemctl disable firewalld
[root@localhost mysql]# sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
[root@localhost mysql]# setenforce 0
2.配置my.cnf
在mysql启动初始化前,一定要确认根据自己所需的MySQL参数,是否需要修改my.cnf文件,比如区分表名大小写,在MySQL8.0之前,是可以在mysql启动后进行重新修改的,但是8.0之后,只能在MySQL启动前进行配置,所以强烈建议,在第一次初始化启动MySQL前,先进行配置my.cnf
[client] port = 3306
socket = /mysql/tmp/mysql.sock
[mysql]
prompt="\u@db \R:\m:\s [\d]> "
no-auto-rehash
[mysqld]
user = mysql
port = 3306
basedir = /usr/
datadir = /mysql/data
socket = /mysql/tmp/mysql.sock
pid-file = /mysql/tmp/mysql.pid
character-set-server=utf8mb4
collation-server = utf8mb4_general_ci
sql_mode='NO_UNSIGNED_SUBTRACTION,NO_ENGINE_SUBSTITUTION'
open_files_limit = 65535
innodb_open_files = 65535
back_log=1024
max_connections = 512
max_connect_errors=1000000
interactive_timeout=300
wait_timeout=300
max_allowed_packet = 1024M
secure_file_priv=''
log-error=/mysql/log/error.log
slow_query_log=ON
slow_query_log_file=/mysql/log/slow_mysql.log
long_query_time=2
innodb_flush_log_at_trx_commit=1
innodb_log_file_size =1G
innodb_log_files_in_group=3
log-bin-trust-function-creators=1
sync_binlog = 1
binlog_cache_size = 16M
max_binlog_cache_size = 1G
max_binlog_size=1G
binlog_format=row
binlog_row_image=full
server-id = 1
# 大小根据实际系统内存情况而定
innodb_buffer_pool_size=4G
innodb_buffer_pool_instances=2
3.执行MySQL初始化,并获取root账户初始密码
依次执行命令:
初始化mysql:mysqld --initialize --user=mysql
获取密码:
[root@localhost mysql]# cat error.log |grep password
2024-06-26T16:32:55.436016+08:00 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: pFtK*VLk!8W1
4.修改root密码
修改root密码
使用默认密码登陆后,需要强制修改初始化默认的登陆密码,不然会出现如下错误:
root@db 09:36: [(none)]> alter user 'root'@'localhost' identified by '111111';
Query OK, 0 rows affected (0.01 sec)
授权远程
USE mysql;
UPDATE mysql.user SET host = '%' WHERE user = 'root';
SELECT user, host, plugin, authentication_string FROM mysql.user;
FLUSH PRIVILEGES;
5.开机自动
配置开机启动启动(可选)
安装MySQL之后,默认为不自启,需要手动开启
# 查看MySQL是否自启:systemctl is-enabled mysqld
# 开启自启 :systemctl enable mysqld
# 关闭自启 :systemctl disable mysqld
6.登录