RPM方式安装mysql

下载离线版本mysql。

mysql-5.7.33-1.el7.x86_64.rpm-bundle.tar

解压

 26468960 Dec 11  2020 mysql-community-client-5.7.33-1.el7.x86_64.rpm
   315280 Dec 11  2020 mysql-community-common-5.7.33-1.el7.x86_64.rpm
  3918736 Dec 11  2020 mysql-community-devel-5.7.33-1.el7.x86_64.rpm
 47513604 Dec 11  2020 mysql-community-embedded-5.7.33-1.el7.x86_64.rpm
 23261952 Dec 11  2020 mysql-community-embedded-compat-5.7.33-1.el7.x86_64.rpm
131045776 Dec 11  2020 mysql-community-embedded-devel-5.7.33-1.el7.x86_64.rpm
  2458780 Dec 11  2020 mysql-community-libs-5.7.33-1.el7.x86_64.rpm
  1260364 Dec 11  2020 mysql-community-libs-compat-5.7.33-1.el7.x86_64.rpm
181817592 Dec 11  2020 mysql-community-server-5.7.33-1.el7.x86_64.rpm
125021984 Dec 11  2020 mysql-community-test-5.7.33-1.el7.x86_64.rpm

安装

# sudo rpm -ivh mysql-com*.rpm
warning: mysql-community-client-5.7.33-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
        mariadb-libs is obsoleted by mysql-community-libs-5.7.33-1.el7.x86_64
        mariadb-libs is obsoleted by mysql-community-libs-compat-5.7.33-1.el7.x86_64
        perl(JSON) is needed by mysql-community-test-5.7.33-1.el7.x86_64

因为mysql的server端须要perl语言的支持,所以咱们还须要在系统中安装perl支持:

安装依赖perl

# sudo yum install perl -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                                       | 3.6 kB  00:00:00     
docker-ce-stable                                                                                                                           | 3.5 kB  00:00:00     
extras                                                                                                                                     | 2.9 kB  00:00:00     
updates                                                                                                                                    | 2.9 kB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package perl.x86_64 4:5.16.3-297.el7 will be updated
---> Package perl.x86_64 4:5.16.3-299.el7_9 will be an update
--> Processing Dependency: perl-libs = 4:5.16.3-299.el7_9 for package: 4:perl-5.16.3-299.el7_9.x86_64
--> Running transaction check
---> Package perl-libs.x86_64 4:5.16.3-297.el7 will be updated
---> Package perl-libs.x86_64 4:5.16.3-299.el7_9 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================================================
 Package                              Arch                              Version                                          Repository                          Size
==================================================================================================================================================================
Updating:
 perl                                 x86_64                            4:5.16.3-299.el7_9                               updates                            8.0 M
Updating for dependencies:
 perl-libs                            x86_64                            4:5.16.3-299.el7_9                               updates                            690 k

Transaction Summary
==================================================================================================================================================================
Upgrade  1 Package (+1 Dependent package)

Total download size: 8.6 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/2): perl-libs-5.16.3-299.el7_9.x86_64.rpm                                                                                               | 690 kB  00:00:02     
(2/2): perl-5.16.3-299.el7_9.x86_64.rpm                                                                                                    | 8.0 MB  00:00:21     
------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                             416 kB/s | 8.6 MB  00:00:21     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : 4:perl-libs-5.16.3-299.el7_9.x86_64                                                                                                            1/4 
  Updating   : 4:perl-5.16.3-299.el7_9.x86_64                                                                                                                 2/4 
  Cleanup    : 4:perl-libs-5.16.3-297.el7.x86_64                                                                                                              3/4 
  Cleanup    : 4:perl-5.16.3-297.el7.x86_64                                                                                                                   4/4 
  Verifying  : 4:perl-5.16.3-299.el7_9.x86_64                                                                                                                 1/4 
  Verifying  : 4:perl-libs-5.16.3-299.el7_9.x86_64                                                                                                            2/4 
  Verifying  : 4:perl-5.16.3-297.el7.x86_64                                                                                                                   3/4 
  Verifying  : 4:perl-libs-5.16.3-297.el7.x86_64                                                                                                              4/4 

Updated:
  perl.x86_64 4:5.16.3-299.el7_9                                                                                                                                  

Dependency Updated:
  perl-libs.x86_64 4:5.16.3-299.el7_9                                                                                                                             

Complete!

一条条安装

# sudo rpm -ivh mysql-community-common-5.7.33-1.el7.x86_64.rpm 
warning: mysql-community-common-5.7.33-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
        file /usr/share/mysql/czech/errmsg.sys from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/danish/errmsg.sys from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/dutch/errmsg.sys from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/english/errmsg.sys from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/estonian/errmsg.sys from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/french/errmsg.sys from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/german/errmsg.sys from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/greek/errmsg.sys from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/hungarian/errmsg.sys from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/italian/errmsg.sys from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/japanese/errmsg.sys from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/korean/errmsg.sys from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/norwegian-ny/errmsg.sys from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/norwegian/errmsg.sys from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/polish/errmsg.sys from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/portuguese/errmsg.sys from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/romanian/errmsg.sys from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/russian/errmsg.sys from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/serbian/errmsg.sys from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/slovak/errmsg.sys from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/spanish/errmsg.sys from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/swedish/errmsg.sys from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/ukrainian/errmsg.sys from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/Index.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/armscii8.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/ascii.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/cp1250.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/cp1251.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/cp1256.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/cp1257.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/cp850.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/cp852.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/cp866.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/dec8.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/geostd8.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/greek.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/hebrew.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/hp8.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/keybcs2.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/koi8r.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/koi8u.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/latin1.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/latin2.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/latin5.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/latin7.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/macce.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/macroman.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
        file /usr/share/mysql/charsets/swe7.xml from install of mysql-community-common-5.7.33-1.el7.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64

这是跟mariadb-libs 冲突了,如果确定没有使用mariadb-libs,yum remove 卸载掉。

安装冲突,解决冲突

# yum info mariadb*
Loaded plugins: fastestmirror
Skipping unreadable repository '/etc/yum.repos.d/Centos-7.repo'
Determining fastest mirrors
docker-ce-stable                                                                                                                                                   | 3.5 kB  00:00:00     
(1/2): docker-ce-stable/7/x86_64/updateinfo                                                                                                                        |   55 B  00:00:00     
(2/2): docker-ce-stable/7/x86_64/primary_db                                                                                                                        | 152 kB  00:00:00     
Installed Packages
Name        : mariadb-libs
Arch        : x86_64
Epoch       : 1
Version     : 5.5.68
Release     : 1.el7
Size        : 4.4 M
Repo        : installed
From repo   : anaconda
Summary     : The shared libraries required for MariaDB/MySQL clients
URL         : http://mariadb.org
License     : GPLv2 with exceptions and LGPLv2 and BSD
Description : The mariadb-libs package provides the essential shared libraries for any
            : MariaDB/MySQL client program or interface. You will need to install this
            : package to use any other MariaDB package or any clients that need to connect
            : to a MariaDB/MySQL server. MariaDB is a community developed branch of MySQL.

卸载冲突插件

# sudo yum -y remove mariadb-libs
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.68-1.el7 will be erased
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 1:net-snmp-agent-libs-5.7.2-49.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-9.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 1:net-snmp-5.7.2-49.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 1:net-snmp-agent-libs-5.7.2-49.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-9.el7.x86_64
--> Processing Dependency: mysql-libs for package: 1:net-snmp-5.7.2-49.el7.x86_64
--> Running transaction check
---> Package net-snmp.x86_64 1:5.7.2-49.el7 will be erased
---> Package net-snmp-agent-libs.x86_64 1:5.7.2-49.el7 will be erased
---> Package postfix.x86_64 2:2.10.1-9.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================================================================================================================
 Package                                            Arch                                  Version                                         Repository                                 Size
==========================================================================================================================================================================================
Removing:
 mariadb-libs                                       x86_64                                1:5.5.68-1.el7                                  @anaconda                                 4.4 M
Removing for dependencies:
 net-snmp                                           x86_64                                1:5.7.2-49.el7                                  @loc-cdrom                                850 k
 net-snmp-agent-libs                                x86_64                                1:5.7.2-49.el7                                  @loc-cdrom                                2.1 M
 postfix                                            x86_64                                2:2.10.1-9.el7                                  @anaconda                                  12 M

Transaction Summary
==========================================================================================================================================================================================
Remove  1 Package (+3 Dependent packages)

Installed size: 20 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : 1:net-snmp-5.7.2-49.el7.x86_64                                                                                                                                         1/4 
warning: /etc/sysconfig/snmpd saved as /etc/sysconfig/snmpd.rpmsave
warning: /etc/snmp/snmpd.conf saved as /etc/snmp/snmpd.conf.rpmsave
  Erasing    : 1:net-snmp-agent-libs-5.7.2-49.el7.x86_64                                                                                                                              2/4 
  Erasing    : 2:postfix-2.10.1-9.el7.x86_64                                                                                                                                          3/4 
  Erasing    : 1:mariadb-libs-5.5.68-1.el7.x86_64                                                                                                                                     4/4 
  Verifying  : 1:net-snmp-5.7.2-49.el7.x86_64                                                                                                                                         1/4 
  Verifying  : 1:net-snmp-agent-libs-5.7.2-49.el7.x86_64                                                                                                                              2/4 
  Verifying  : 1:mariadb-libs-5.5.68-1.el7.x86_64                                                                                                                                     3/4 
  Verifying  : 2:postfix-2.10.1-9.el7.x86_64                                                                                                                                          4/4 

Removed:
  mariadb-libs.x86_64 1:5.5.68-1.el7                                                                                                                                                      

Dependency Removed:
  net-snmp.x86_64 1:5.7.2-49.el7                            net-snmp-agent-libs.x86_64 1:5.7.2-49.el7                            postfix.x86_64 2:2.10.1-9.el7                           

Complete!

重新rpm -ivh xx.rpm

# sudo rpm -ivh mysql-community-common-5.7.33-1.el7.x86_64.rpm 
warning: mysql-community-common-5.7.33-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-5.7.33-1.e################################# [100%]

# sudo rpm -ivh mysql-community-libs-
mysql-community-libs-5.7.33-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.33-1.el7.x86_64.rpm

# sudo rpm -ivh mysql-community-libs-5.7.33-1.el7.x86_64.rpm 
warning: mysql-community-libs-5.7.33-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-5.7.33-1.el7################################# [100%]

# sudo rpm -ivh mysql-community-client-5.7.33-1.el7.x86_64.rpm 
warning: mysql-community-client-5.7.33-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-5.7.33-1.e################################# [100%]

# sudo rpm -ivh mysql-community-server-5.7.33-1.el7.x86_64.rpm 
warning: mysql-community-server-5.7.33-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-5.7.33-1.e################################# [100%]

启动与检查

# systemctl start mysqld
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to manage system services or units.
Authenticating as: root
Password: 
==== AUTHENTICATION COMPLETE ===

# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2024-07-04 14:12:38 CST; 3s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 28604 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 28371 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 28607 (mysqld)
    Tasks: 27
   Memory: 297.6M
   CGroup: /system.slice/mysqld.service
           └─28607 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

查找初始密码

# sudo grep 'temporary' /var/log/mysqld.log 
2024-07-04T06:12:30.791185Z 1 [Note] A temporary password is generated for root@localhost: WOoB<rtXW5qo
2024-07-04T06:12:37.291448Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables

登陆mysql

# mysql -uroot -p'WOoB<rtXW5qo'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.33

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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 databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> 

修改root密码,

mysql> set password = password('xxx');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set password = password('xxxxxxxxxxx');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> exit
Bye

并设置可远程访问

mysql> grant all privileges on *.* to root@'%' identified by 'ddddddd' with grant option;
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

检查mysql.user

mysql> select user,host,authentication_string from mysql.user;
+---------------+-----------+-------------------------------------------+
| user          | host      | authentication_string                     |
+---------------+-----------+-------------------------------------------+
| root          | localhost | *B695B6F7FED8C46D8F21663E20B4E0BA549BCEEA |
| mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.sys     | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| root          | %         | *B695B6F7FED8C46D8F21663E20B4E0BA549BCEEA |
+---------------+-----------+-------------------------------------------+
4 rows in set (0.01 sec)

安装完mysql后,修改data目录

方式一:

mysqld --default-file=/etc/my.cnf --datadir=/data01/mysql --user=mysql --initialize

 在初始化的时候,就将路径指定到数据盘上,而不是默认的/var/lib/mysql下。

方式二:

my.cnf默认文件位置

# ll /etc/my.cnf
-rw-r--r-- 1 root root 960 Dec 10  2020 /etc/my.cnf

data默认文件位置

# ll /var/lib/mysql
total 122952
-rw-r----- 1 mysql mysql       56 Jul  4 14:12 auto.cnf
-rw------- 1 mysql mysql     1676 Jul  4 14:12 ca-key.pem
-rw-r--r-- 1 mysql mysql     1112 Jul  4 14:12 ca.pem
-rw-r--r-- 1 mysql mysql     1112 Jul  4 14:12 client-cert.pem
-rw------- 1 mysql mysql     1680 Jul  4 14:12 client-key.pem
-rw-r----- 1 mysql mysql      436 Jul  4 14:12 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 Jul  4 14:12 ibdata1
-rw-r----- 1 mysql mysql 50331648 Jul  4 14:12 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 Jul  4 14:12 ib_logfile1
-rw-r----- 1 mysql mysql 12582912 Jul  4 14:12 ibtmp1
drwxr-x--- 2 mysql mysql     4096 Jul  4 14:12 mysql
srwxrwxrwx 1 mysql mysql        0 Jul  4 14:12 mysql.sock
-rw------- 1 mysql mysql        6 Jul  4 14:12 mysql.sock.lock
drwxr-x--- 2 mysql mysql     8192 Jul  4 14:12 performance_schema
-rw------- 1 mysql mysql     1676 Jul  4 14:12 private_key.pem
-rw-r--r-- 1 mysql mysql      452 Jul  4 14:12 public_key.pem
-rw-r--r-- 1 mysql mysql     1112 Jul  4 14:12 server-cert.pem
-rw------- 1 mysql mysql     1680 Jul  4 14:12 server-key.pem
drwxr-x--- 2 mysql mysql     8192 Jul  4 14:12 sys

停止mysql

# systemctl stop mysqld

# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Thu 2024-07-04 15:23:36 CST; 4s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 28604 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 28371 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 28607 (code=exited, status=0/SUCCESS)

Jul 04 14:12:17 host-10-15-32-71 systemd[1]: Starting MySQL Server...
Jul 04 14:12:38 host-10-15-32-71 systemd[1]: Started MySQL Server.
Jul 04 15:23:34 host-10-15-32-71 systemd[1]: Stopping MySQL Server...
Jul 04 15:23:36 host-10-15-32-71 systemd[1]: Stopped MySQL Server.

复制原数据到新目录

# cp -R /var/lib/mysql /data/datamysql/

修改my.cnf,指定新目录

datadir=/data/datamysql/mysql

启动mysql

# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2024-07-04 15:32:35 CST; 13min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 27299 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 27275 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 27301 (mysqld)
    Tasks: 28
   Memory: 193.9M
   CGroup: /system.slice/mysqld.service
           └─27301 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值