MySQL 5.7.31 RPM方式 step by step install

[root@almalinux ~]# rpm -qa | grep -i mariadb

[root@almalinux ~]# 安装前检查卸载以上

-bash: 安装前检查卸载以上: 未找到命令

[root@almalinux ~]# 

[root@almalinux ~]# 

[root@almalinux ~]# 

[root@almalinux ~]# ls /var/lib/mysql

ls: 无法访问'/var/lib/mysql': 没有那个文件或目录

[root@almalinux ~]# ls /var/log/mysqld.log

ls: 无法访问'/var/log/mysqld.log': 没有那个文件或目录

[root@almalinux ~]# ls /etc/my.cnf

ls: 无法访问'/etc/my.cnf': 没有那个文件或目录

[root@almalinux ~]# rpm -qa | grep libaio

libaio-0.3.112-1.el8.x86_64

[root@almalinux ~]# rpm -qa | grep net-tools

net-tools-2.0-0.52.20160912git.el8.x86_64


安装MySQL(注意安装顺序,否则有依赖告警)

[root@localhost ~]# rpm -ivh mysql-community-common-5.7.31-1.el7.x86_64.rpm

[root@localhost ~]# rpm -ivh mysql-community-libs-5.7.31-1.el7.x86_64.rpm

[root@localhost ~]# rpm -ivh mysql-community-libs-5.7.31-1.el7.x86_64.rpm

[root@localhost ~]# rpm -ivh mysql-community-client-5.7.31-1.el7.x86_64.rpm

[root@localhost ~]# rpm -ivh mysql-community-server-5.7.31-1.el7.x86_64.rpm


[root@almalinux ~]# rpm -ivh mysql-community-client-5.7.31-1.el7.x86_64.rpm

警告:mysql-community-client-5.7.31-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY

错误:依赖检测失败:

        libncurses.so.5()(64bit) 被 mysql-community-client-5.7.31-1.el7.x86_64 需要

        libtinfo.so.5()(64bit) 被 mysql-community-client-5.7.31-1.el7.x86_64 需要

        

--以上依赖包要安装

[root@almalinux ~]# yum install libncurses*

[root@almalinux ~]# yum install libtinfo*



--server 安装后提示

[/usr/lib/tmpfiles.d/elasticsearch.conf:1] Line references path below legacy directory /var/run/, updating /var/run/elasticsearch → /run/elasticsearch; please update the tmpfiles.d/ drop-in file accordingly.

[/usr/lib/tmpfiles.d/mysql.conf:23] Line references path below legacy directory /var/run/, updating /var/run/mysqld → /run/mysqld; please update the tmpfiles.d/ drop-in file accordingly.


[root@almalinux ~]# mysqladmin --version

mysqladmin  Ver 8.42 Distrib 5.7.31, for Linux on x86_64



[root@almalinux ~]# systemctl start mysqld.service 


[root@almalinux ~]# systemctl status mysqld.service 

● mysqld.service - MySQL Server

   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)

   Active: active (running) since Fri 2023-06-09 05:42:16 EDT; 1min 4s ago

     Docs: man:mysqld(8)

           http://dev.mysql.com/doc/refman/en/using-systemd.html

  Process: 31834 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)

  Process: 31778 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)

 Main PID: 31836 (mysqld)

    Tasks: 27 (limit: 23628)

   Memory: 347.0M

   CGroup: /system.slice/mysqld.service

           └─31836 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid


6月 09 05:42:06 almalinux.test.com systemd[1]: Starting MySQL Server...

6月 09 05:42:16 almalinux.test.com systemd[1]: Started MySQL Server.


--安装后默认的初始密码

[root@almalinux ~]# grep 'temporary password' /var/log/mysqld.log

2023-06-09T09:42:12.811471Z 1 [Note] A temporary password is generated for root@localhost: f>c:x1Yd3j>1



mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'passWWord';

Query OK, 0 rows affected (0.00 sec)


mysql> quit

Bye

[root@almalinux ~]# systemctl restart mysqld.service                    

[root@almalinux ~]# mysql -uroot -p                              

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.7.31 MySQL Community Server (GPL)


Copyright (c) 2000, 2020, 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> SHOW VARIABLES LIKE 'character%';

+--------------------------+----------------------------+

| Variable_name            | Value                      |

+--------------------------+----------------------------+

| character_set_client     | utf8                       |

| character_set_connection | utf8                       |

| character_set_database   | latin1                     |

| character_set_filesystem | binary                     |

| character_set_results    | utf8                       |

| character_set_server     | latin1                     |

| character_set_system     | utf8                       |

| character_sets_dir       | /usr/share/mysql/charsets/ |

+--------------------------+----------------------------+

8 rows in set (0.01 sec)



--my.cnf

[root@almalinux ~]# more /etc/my.cnf

[client]

default-character-set=utf8

# For advice on how to change settings please see

# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html


[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

character-set-server=utf8

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock


# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0


log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

validate_password = off


--修改完成配置文件后重启生效

[root@almalinux ~]# systemctl restart mysqld.service



[root@almalinux ~]# mysql -uroot -p

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 3

Server version: 5.7.31 MySQL Community Server (GPL)


Copyright (c) 2000, 2020, 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> SHOW VARIABLES LIKE 'character%';

+--------------------------+----------------------------+

| Variable_name            | Value                      |

+--------------------------+----------------------------+

| character_set_client     | utf8                       |

| character_set_connection | utf8                       |

| character_set_database   | utf8                       |

| character_set_filesystem | binary                     |

| character_set_results    | utf8                       |

| character_set_server     | utf8                       |

| character_set_system     | utf8                       |

| character_sets_dir       | /usr/share/mysql/charsets/ |

+--------------------------+----------------------------+

8 rows in set (0.00 sec)



--接下来,初始化。

--如在已有生产数据前提下,注意数据位置初始化时会被覆盖。


请使用浏览器的分享功能分享到微信等