文章目录
- 一 查看linux操作系统版本和系统内核版本
- 二 下载rpm安装包
- 1. 网页下载地址
- 2. 服务器直接下载
- 三 查看已安装的mysql,并卸载
- 1. 查看已有的mysql组件
- 2. 卸载mysql组件
- 四 安装新的mysql组件
- 异常1
- 异常2
- 8.0版本及以上组件安装顺序
- 五 登录mysql并修改初始密码
- 1. 启动mysql
- 2. 登录mysql并修改密码
- 六 其他问题
- MYSQL安装后Navicat连接报1146错误解决方案
一 查看linux操作系统版本和系统内核版本
[root@slave1 ~]# cat /etc/redhat-release 查看操作系统版本
CentOS Linux release 7.5.1804 (Core)
[root@slave1 ~]# uname -r 查看系统内核版本
3.10.0-862.el7.x86_64
二 下载rpm安装包
1. 网页下载地址
下载地址: mysql
2. 服务器直接下载
[root@slave1 ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar
- 下载需要的mysql组件,有4个:分别是 server、client、common、libs
三 查看已安装的mysql,并卸载
1. 查看已有的mysql组件
- 会列出旧版本mysql的组件列表,可能为多个
rpm -qa | grep -i mysql
2. 卸载mysql组件
- 分别卸载出现的对应组件,包括server、client、common、libs
yum remove mysql-community-server-5.7.29-1.el7.x86_64
四 安装新的mysql组件
- 使用命令rpm -ivh {-file-name}进行安装操作。
异常1
- 安装libs时出错
mysql-community-common(x86-64) >= 5.7.9 is needed by mysql-community-libs-5.7.29-1.el7.x86_64
- 原因:mysql组件安装要遵循一定的顺序,依赖关系依次为common→libs→client→server
rpm -ivh mysql-community-common-5.7.29-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.29-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.29-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.29-1.el7.x86_64.rpm
- 先安装common
ok:
rpm -ivh mysql-community-common-5.7.29-1.el7.x86_64.rpm
warning: mysql-community-common-5.7.29-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
异常2
- 安装libs时又报错
MySQL-shared < 5.7.29-1.el7 is obsoleted by mysql-community-libs-5.7.29-1.el7.x86_64
error: Failed dependencies:
libmysqlclient.so.18()(64bit) is needed by (installed) perl-DBD-MySQL-4.023-6.el7.x86_64
libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-7.el7.x86_64
libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) perl-DBD-MySQL-4.023-6.el7.x86_64
libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-7.el7.x86_64
- 原因是服务器里还有低于5.7.29的libs组件,它已经与common绑定依赖,故安装5.7.29时依赖失败
- 解决:删除低版本冲突的组件,我这里冲突的是5.6.44
# 强力删除
rpm -e MySQL-shared-5.6.44-1.el7.x86_64 --nodeps
# 也可以把命令后面直接加--nodeps --force
rpm -ivh mysql-community-server-5.7.29-1.el7.x86_64.rpm --nodeps --force
- 安装libs组件ok
ok: 1:mysql-community-libs-5.7.29-1.el7################################# [100%]
8.0版本及以上组件安装顺序
- 升级到mysql8之后发现对应顺序有较大调整,特此更正,安装版本号为:8.0.33
#首先依旧是安装common
rpm -ivh ./mysql-community-common-8.0.33-1.el7.x86_64.rpm
#下面新增新组件
rpm -ivh ./mysql-community-client-plugins-8.0.33-1.el7.x86_64.rpm
#libs
rpm -ivh ./mysql-community-libs-8.0.33-1.el7.x86_64.rpm
#client
rpm -ivh ./mysql-community-client-8.0.33-1.el7.x86_64.rpm
#server前置组件
rpm -ivh ./mysql-community-icu-data-files-8.0.33-1.el7.x86_64.rpm
#server
rpm -ivh ./mysql-community-server-8.0.33-1.el7.x86_64.rpm
#查询mysql组件
rpm -qa | grep -i mysql
mysql-community-common-8.0.33-1.el7.x86_64
mysql-community-libs-8.0.33-1.el7.x86_64
mysql-community-icu-data-files-8.0.33-1.el7.x86_64
mysql80-community-release-el7-7.noarch
mysql-community-client-plugins-8.0.33-1.el7.x86_64
mysql-community-client-8.0.33-1.el7.x86_64
mysql-community-server-8.0.33-1.el7.x86_64
- 安装完成后检测是否成功
mysqladmin --version
mysqladmin Ver 8.0.33 for Linux on x86_64 (MySQL Community Server - GPL)
五 登录mysql并修改初始密码
1. 启动mysql
- 安装完后,使用命令 service mysqld start 或 systemctl start mysqld.service 启动MySQL服务。
systemctl start mysqld.service 启动mysql
systemctl status mysqld.service 查看mysql状态
systemctl stop mysqld.service 关闭mysql
2. 登录mysql并修改密码
- mysql在安装过程中,会在安装日志中生成一个临时密码。
# 获取临时密码
grep 'temporary password' /var/log/mysqld.log
# 即可查询到类似于如下的一条日志记录:
2020-06-18T10:17:25.579753Z 1 [Note] A temporary password is generated for root@localhost: XqWlxlV3p.a8
- XqWlxlV3p.a8即为登录密码。
- 登录mysql
[root@slave1 tools]# 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.29
Copyright (c) 2000, 2018, 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.
# 设置密码为123456
mysql> set password for root@localhost=password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
# 8.0以上版本修改root使用如下命令
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.04 sec)
# 授予root用户远程登录权限
mysql> grant all privileges on *.* to root@'%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.05 sec)
# 8.0以上命令更正
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges; # 刷新权限
Query OK, 0 rows affected (0.36 sec)
mysql> quit # 输入quit 或 exit 都能退出mysql
Bye
六 其他问题
MYSQL安装后Navicat连接报1146错误解决方案
- 原因:mysql的部分系统表不存在
- 解决:更新mysql文件并重启
#更新
mysql mysql_upgrade -u root -p --force
#重启
mysql systemctl stop mysqld.service
systemctl start mysqld.service