如果你只是安装测试环境,或者一些不重要的环境,建议使用这种rpm安装,非常简单方便,
1.下载mysql安装包
mysql安装包地址为:
https://dev.mysql.com/downloads/mysql/5.7.html#downloads
这里我下载的是5.7.28,使用rpm安装,下载RPM Bundle
2.安装mysql
使用rpm安装非常简单,解压缩下载的安装包,使用yum进行安装
yum localinstall -y mysql-comm*
[root@mysql57 soft]# yum localinstall mysql-community-*
Loaded plugins: fastestmirror, langpacks
Examining mysql-community-client-5.7.28-1.el7.x86_64.rpm: mysql-community-client-5.7.28-1.el7.x86_64
Marking mysql-community-client-5.7.28-1.el7.x86_64.rpm to be installed
Examining mysql-community-common-5.7.28-1.el7.x86_64.rpm: mysql-community-common-5.7.28-1.el7.x86_64
Marking mysql-community-common-5.7.28-1.el7.x86_64.rpm to be installed
Examining mysql-community-devel-5.7.28-1.el7.x86_64.rpm: mysql-community-devel-5.7.28-1.el7.x86_64
Marking mysql-community-devel-5.7.28-1.el7.x86_64.rpm to be installed
Examining mysql-community-embedded-5.7.28-1.el7.x86_64.rpm: mysql-community-embedded-5.7.28-1.el7.x86_64
Marking mysql-community-embedded-5.7.28-1.el7.x86_64.rpm to be installed
Examining mysql-community-embedded-compat-5.7.28-1.el7.x86_64.rpm: mysql-community-embedded-compat-5.7.28-1.el7.x86_64
Marking mysql-community-embedded-compat-5.7.28-1.el7.x86_64.rpm to be installed
Examining mysql-community-embedded-devel-5.7.28-1.el7.x86_64.rpm: mysql-community-embedded-devel-5.7.28-1.el7.x86_64
Marking mysql-community-embedded-devel-5.7.28-1.el7.x86_64.rpm to be installed
Examining mysql-community-libs-5.7.28-1.el7.x86_64.rpm: mysql-community-libs-5.7.28-1.el7.x86_64
Marking mysql-community-libs-5.7.28-1.el7.x86_64.rpm to be installed
Examining mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm: mysql-community-libs-compat-5.7.28-1.el7.x86_64
Marking mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm to be installed
Examining mysql-community-server-5.7.28-1.el7.x86_64.rpm: mysql-community-server-5.7.28-1.el7.x86_64
Marking mysql-community-server-5.7.28-1.el7.x86_64.rpm to be installed
Examining mysql-community-test-5.7.28-1.el7.x86_64.rpm: mysql-community-test-5.7.28-1.el7.x86_64
Marking mysql-community-test-5.7.28-1.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.60-1.el7_5 will be obsoleted
---> Package mysql-community-client.x86_64 0:5.7.28-1.el7 will be installed
---> Package mysql-community-common.x86_64 0:5.7.28-1.el7 will be installed
---> Package mysql-community-devel.x86_64 0:5.7.28-1.el7 will be installed
---> Package mysql-community-embedded.x86_64 0:5.7.28-1.el7 will be installed
---> Package mysql-community-embedded-compat.x86_64 0:5.7.28-1.el7 will be installed
---> Package mysql-community-embedded-devel.x86_64 0:5.7.28-1.el7 will be installed
---> Package mysql-community-libs.x86_64 0:5.7.28-1.el7 will be obsoleting
---> Package mysql-community-libs-compat.x86_64 0:5.7.28-1.el7 will be obsoleting
---> Package mysql-community-server.x86_64 0:5.7.28-1.el7 will be installed
---> Package mysql-community-test.x86_64 0:5.7.28-1.el7 will be installed
--> Processing Dependency: perl(Data::Dumper) for package: mysql-community-test-5.7.28-1.el7.x86_64
Loading mirror speeds from cached hostfile
ISO-DVD | 3.6 kB 00:00:00
--> Processing Dependency: perl(Data::Dumper) for package: mysql-community-test-5.7.28-1.el7.x86_64
--> Processing Dependency: perl(JSON) for package: mysql-community-test-5.7.28-1.el7.x86_64
--> Processing Dependency: perl(JSON) for package: mysql-community-test-5.7.28-1.el7.x86_64
--> Running transaction check
---> Package perl-Data-Dumper.x86_64 0:2.145-3.el7 will be installed
---> Package perl-JSON.noarch 0:2.59-2.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================================================================================================================================================================
Package Arch Version Repository Size
======================================================================================================================================================================================================================================
Installing:
mysql-community-client x86_64 5.7.28-1.el7 /mysql-community-client-5.7.28-1.el7.x86_64 175 M
mysql-community-common x86_64 5.7.28-1.el7 /mysql-community-common-5.7.28-1.el7.x86_64 2.8 M
mysql-community-devel x86_64 5.7.28-1.el7 /mysql-community-devel-5.7.28-1.el7.x86_64 36 M
mysql-community-embedded x86_64 5.7.28-1.el7 /mysql-community-embedded-5.7.28-1.el7.x86_64 207 M
mysql-community-embedded-compat x86_64 5.7.28-1.el7 /mysql-community-embedded-compat-5.7.28-1.el7.x86_64 88 M
mysql-community-embedded-devel x86_64 5.7.28-1.el7 /mysql-community-embedded-devel-5.7.28-1.el7.x86_64 916 M
mysql-community-libs x86_64 5.7.28-1.el7 /mysql-community-libs-5.7.28-1.el7.x86_64 17 M
replacing mariadb-libs.x86_64 1:5.5.60-1.el7_5
mysql-community-libs-compat x86_64 5.7.28-1.el7 /mysql-community-libs-compat-5.7.28-1.el7.x86_64 6.2 M
replacing mariadb-libs.x86_64 1:5.5.60-1.el7_5
mysql-community-server x86_64 5.7.28-1.el7 /mysql-community-server-5.7.28-1.el7.x86_64 868 M
mysql-community-test x86_64 5.7.28-1.el7 /mysql-community-test-5.7.28-1.el7.x86_64 700 M
Installing for dependencies:
perl-Data-Dumper x86_64 2.145-3.el7 ISO-DVD 47 k
perl-JSON noarch 2.59-2.el7 ISO-DVD 96 k
Transaction Summary
======================================================================================================================================================================================================================================
Install 10 Packages (+2 Dependent packages)
Total size: 2.9 G
Total download size: 143 k
Is this ok [y/d/N]: y
Downloading packages:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 1.7 MB/s | 143 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql-community-common-5.7.28-1.el7.x86_64 1/13
Installing : mysql-community-libs-5.7.28-1.el7.x86_64 2/13
Installing : mysql-community-devel-5.7.28-1.el7.x86_64 3/13
Installing : mysql-community-client-5.7.28-1.el7.x86_64 4/13
Installing : mysql-community-server-5.7.28-1.el7.x86_64 5/13
Installing : mysql-community-embedded-5.7.28-1.el7.x86_64 6/13
Installing : perl-Data-Dumper-2.145-3.el7.x86_64 7/13
Installing : perl-JSON-2.59-2.el7.noarch 8/13
Installing : mysql-community-test-5.7.28-1.el7.x86_64 9/13
Installing : mysql-community-embedded-devel-5.7.28-1.el7.x86_64 10/13
Installing : mysql-community-libs-compat-5.7.28-1.el7.x86_64 11/13
Installing : mysql-community-embedded-compat-5.7.28-1.el7.x86_64 12/13
Erasing : 1:mariadb-libs-5.5.60-1.el7_5.x86_64 13/13
Verifying : mysql-community-test-5.7.28-1.el7.x86_64 1/13
Verifying : mysql-community-embedded-devel-5.7.28-1.el7.x86_64 2/13
Verifying : perl-JSON-2.59-2.el7.noarch 3/13
Verifying : perl-Data-Dumper-2.145-3.el7.x86_64 4/13
Verifying : mysql-community-devel-5.7.28-1.el7.x86_64 5/13
Verifying : mysql-community-libs-compat-5.7.28-1.el7.x86_64 6/13
Verifying : mysql-community-common-5.7.28-1.el7.x86_64 7/13
Verifying : mysql-community-embedded-5.7.28-1.el7.x86_64 8/13
Verifying : mysql-community-embedded-compat-5.7.28-1.el7.x86_64 9/13
Verifying : mysql-community-libs-5.7.28-1.el7.x86_64 10/13
Verifying : mysql-community-client-5.7.28-1.el7.x86_64 11/13
Verifying : mysql-community-server-5.7.28-1.el7.x86_64 12/13
Verifying : 1:mariadb-libs-5.5.60-1.el7_5.x86_64 13/13
Installed:
mysql-community-client.x86_64 0:5.7.28-1.el7 mysql-community-common.x86_64 0:5.7.28-1.el7 mysql-community-devel.x86_64 0:5.7.28-1.el7 mysql-community-embedded.x86_64 0:5.7.28-1.el7
mysql-community-embedded-compat.x86_64 0:5.7.28-1.el7 mysql-community-embedded-devel.x86_64 0:5.7.28-1.el7 mysql-community-libs.x86_64 0:5.7.28-1.el7 mysql-community-libs-compat.x86_64 0:5.7.28-1.el7
mysql-community-server.x86_64 0:5.7.28-1.el7 mysql-community-test.x86_64 0:5.7.28-1.el7
Dependency Installed:
perl-Data-Dumper.x86_64 0:2.145-3.el7 perl-JSON.noarch 0:2.59-2.el7
Replaced:
mariadb-libs.x86_64 1:5.5.60-1.el7_5
Complete!
下面是安装完成之后的,主要的目录信息:
来源: https://dev.mysql.com/doc/refman/5.7/en/linux-installation-rpm.html
Files or Resources | Location |
---|---|
Client programs and scripts | /usr/bin |
mysqld server | /usr/sbin |
Configuration file | /etc/my.cnf |
Data directory | /var/lib/mysql |
Error log file | For RHEL, Oracle Linux, CentOS or Fedora platforms: For SLES: |
Value of secure_file_priv | /var/lib/mysql-files |
System V init script | For RHEL, Oracle Linux, CentOS or Fedora platforms: For SLES: |
Systemd service | For RHEL, Oracle Linux, CentOS or Fedora platforms: For SLES: |
Pid file | /var/run/mysql/mysqld.pid |
Socket | /var/lib/mysql/mysql.sock |
Keyring directory | /var/lib/mysql-keyring |
Unix manual pages | /usr/share/man |
Include (header) files | /usr/include/mysql |
Libraries | /usr/lib/mysql |
Miscellaneous support files (for example, error messages, and character set files) | /usr/share/mysql |
比较重要的是一些目录见上面标红.
默认的数据文件目录是在/var/lib/mysql中.你可以在/etc/my.cnf中进行修改,如果你修改了默认的socket,那么在client选项卡中也需要进行修改client的socket文件位置
建议使用软连接的方式,将你实际的目录连接到/var/lib/mysql,这样直接使用其默认位置.
3.启动mysql
使用systemctl启动mysql,这里systemctl启动之后,会自动创建mysql实例.
[root@mysql57 soft]# systemctl start mysqld
[root@mysql57 soft]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2019-10-22 20:52:45 CST; 24s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 6935 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 6802 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 6938 (mysqld)
Tasks: 27
CGroup: /system.slice/mysqld.service
└─6938 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Oct 22 20:52:15 mysql57 systemd[1]: Starting MySQL Server...
Oct 22 20:52:45 mysql57 systemd[1]: Started MySQL Server.
到此mysql就安装完成了,
安装完成之后,会为root@localhost创建一个默认密码,可以在/var/log/mysqld.log中查看:
2019-10-22T12:52:41.732603Z 1 [Note] A temporary password is generated for root@localhost: ihmAdG05Ro!B
4.修改root密码
使用默认的密码登录到数据库,必须进行修改数据库密码
mysql> alter user root@'localhost' identified by 'Admin@123';
到此mysql就安装完成了.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)