安装方式分类
1.1离线rpm包安装
1.2 yum源安装
离线包安装
Rpm包下载地址:https://dev.mysql.com/downloads/mysql/
下载后,通过rpm -ivh 安装对应rpm包
rpm -ivh mysql-community-server-8.0.32-1.el7.x86_64.rpm
yum源安装
官网参考:https://dev.mysql.com/doc/refman/5.7/en/linux-installation-yum-repo.html
3.1 构建源
[root@localhost space]# wget https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm
# 使用rpm包安装或者yum安装rpm都可以
[root@localhost space]# rpm -ivh mysql80-community-release-el7-7.noarch.rpm
# 或者
[root@localhost space]# yum localinstall mysql80-community-release-el7-7.noarch.rpm
Loaded plugins: fastestmirror, langpacks
Examining mysql80-community-release-el7-7.noarch.rpm: mysql80-community-release-el7-7.noarch
Marking mysql80-community-release-el7-7.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql80-community-release.noarch 0:el7-7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================================
Installing:
mysql80-community-release noarch el7-7 /mysql80-community-release-el7-7.noarch 10 k
Transaction Summary
===============================================================================================================================================================
Install 1 Package
Total size: 10 k
Installed size: 10 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql80-community-release-el7-7.noarch 1/1
Verifying : mysql80-community-release-el7-7.noarch 1/1
Installed:
mysql80-community-release.noarch 0:el7-7
Complete!
3.2 调整源版本
# 查看源版本
[root@localhost space]# yum repolist all | grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 C disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 C disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 C disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 C disabled
mysql-cluster-8.0-community/x86_64 MySQL Cluster 8.0 C disabled
mysql-cluster-8.0-community-debuginfo/x86_64 MySQL Cluster 8.0 C disabled
mysql-cluster-8.0-community-source MySQL Cluster 8.0 C disabled
mysql-connectors-community/x86_64 MySQL Connectors Co enabled: 213
mysql-connectors-community-debuginfo/x86_64 MySQL Connectors Co disabled
mysql-connectors-community-source MySQL Connectors Co disabled
mysql-tools-community/x86_64 MySQL Tools Communi enabled: 96
mysql-tools-community-debuginfo/x86_64 MySQL Tools Communi disabled
mysql-tools-community-source MySQL Tools Communi disabled
mysql-tools-preview/x86_64 MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview disabled
mysql57-community/x86_64 MySQL 5.7 Community enabled: 642
mysql57-community-source MySQL 5.7 Community disabled
mysql80-community/x86_64 MySQL 8.0 Community disabled
mysql80-community-debuginfo/x86_64 MySQL 8.0 Community disabled
mysql80-community-source MySQL 8.0 Community disabled
# 禁用80版本的源,本次安装5.7版本的mysql
[root@localhost space]# yum-config-manager --disable mysql80-community
Loaded plugins: fastestmirror, langpacks
=================================================================== repo: mysql80-community ===================================================================
[mysql80-community]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl = http://repo.mysql.com/yum/mysql-8.0-community/el/7/x86_64
cache = 0
cachedir = /var/cache/yum/x86_64/7/mysql80-community
check_config_file_age = True
compare_providers_priority = 80
cost = 1000
deltarpm_metadata_percentage = 100
deltarpm_percentage =
enabled = False
enablegroups = True
exclude =
failovermethod = priority
ftp_disable_epsv = False
gpgcadir = /var/lib/yum/repos/x86_64/7/mysql80-community/gpgcadir
gpgcakey =
gpgcheck = True
gpgdir = /var/lib/yum/repos/x86_64/7/mysql80-community/gpgdir
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022,
file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
hdrdir = /var/cache/yum/x86_64/7/mysql80-community/headers
http_caching = all
includepkgs =
ip_resolve =
keepalive = True
keepcache = False
mddownloadpolicy = sqlite
mdpolicy = group:small
mediaid =
metadata_expire = 21600
metadata_expire_filter = read-only:present
metalink =
minrate = 0
mirrorlist =
mirrorlist_expire = 86400
name = MySQL 8.0 Community Server
old_base_cache_dir =
password =
persistdir = /var/lib/yum/repos/x86_64/7/mysql80-community
pkgdir = /var/cache/yum/x86_64/7/mysql80-community/packages
proxy = False
proxy_dict =
proxy_password =
proxy_username =
repo_gpgcheck = False
retries = 10
skip_if_unavailable = False
ssl_check_cert_permissions = True
sslcacert =
sslclientcert =
sslclientkey =
sslverify = True
throttle = 0
timeout = 30.0
ui_id = mysql80-community/x86_64
ui_repoid_vars = releasever,
basearch
username =
# 启用57版本的源,本次安装5.7版本的mysql
[root@localhost space]# yum-config-manager --disable mysql57-community
# 验证源版本是否已切换
[root@localhost space]# yum repolist enabled | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community 213
mysql-tools-community/x86_64 MySQL Tools Community 96
mysql57-community/x86_64 MySQL 5.7 Community Server 642
# 验证实际yum包的版本是否5.7
[root@localhost space]# yum list | grep mysql-community-server
mysql-community-server.x86_64 5.7.41-1.el7 mysql57-community
# 安装mysql
[root@localhost space]# yum install mysql-community-server
# 如果安装失败,可以尝试安装报错的依赖包
[root@localhost space]# yum install mysql-community-libs-compat
# 检查安装是否成功
[root@localhost space]# yum list installed | grep mysql
mysql-community-client.x86_64 5.7.41-1.el7 @mysql57-community
mysql-community-common.x86_64 5.7.41-1.el7 @mysql57-community
mysql-community-libs.x86_64 5.7.41-1.el7 @mysql57-community
mysql-community-libs-compat.x86_64 5.7.41-1.el7 @mysql57-community
mysql-community-server.x86_64 5.7.41-1.el7 @mysql57-community
mysql80-community-release.noarch el7-7 installed
启动服务
[root@localhost space]# systemctl start mysqld
[root@localhost space]# ps -ef | grep mysql
mysql 69377 1 11 17:44 ? 00:00:00 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root 69406 42858 0 17:44 pts/4 00:00:00 grep --color=auto mysql
修改密码
# 查询当前密码
[root@localhost space]# grep 'temporary password' /var/log/mysqld.log
2023-03-11T01:44:40.296013Z 1 [Note] A temporary password is generated for root@localhost: 55?3ek;f/b2A
# 登录mysql修改密码
[root@localhost space]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.41
Copyright (c) 2000, 2023, 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> ALTER USER 'root'@'localhost' IDENTIFIED BY 'tooLS;123';
Query OK, 0 rows affected (0.00 sec)
登录验证
[root@localhost space]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.41 MySQL Community Server (GPL)
Copyright (c) 2000, 2023, 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;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
无法连接异常
其他服务器连接时,可能出现如下错误:
is not allowed to connect to this MySQL serverConnection closed by foreign host
需要放开root的远端连接ip限制就好了,如下:
mysql> update user set host = '%' where user ='root';
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)