rpm -qa | grep mysql
Mysql官网:https://www.mysql.com/
下载网址:https://downloads.mysql.com/archives/community/
cat /etc/redhat-release
首先使用第三方工具上传
# 创建一个文件夹,存放mysql
mkdir -p /usr/mysql
cd /usr/mysql
# 在当前目录下(mysql)下创建一个 mysql-5.7.41 文件夹
mkdir mysql-5.7.41
# 解压安装包到该目录下
tar -xvf mysql-5.7.41-1.el7.x86_64.rpm-bundle.tar -C mysql-5.7.41
[root@localhost mysql-5.7.41]# ls
mysql-community-client-5.7.41-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.41-1.el7.x86_64.rpm
mysql-community-server-5.7.41-1.el7.x86_64.rpm
mysql-community-common-5.7.41-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.41-1.el7.x86_64.rpm
mysql-community-test-5.7.41-1.el7.x86_64.rpm
mysql-community-devel-5.7.41-1.el7.x86_64.rpm
mysql-community-libs-5.7.41-1.el7.x86_64.rpm
mysql-community-embedded-5.7.41-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.41-1.el7.x86_64.rpm
解压后的文件都是 rpm 文件,因此需要用到 rpm 包资源管理器相关的指令安装这些 rpm 的安装包
yum install openssl-devel
安装完该插件之后,
依次执行
以下命令安装这些 rpm 包
yum install openssl-devel
rpm -ivh mysql-community-common-5.7.41-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.41-1.el7.x86_64.rpm
yum remove mysql-libs
rpm -ivh mysql-community-libs-compat-5.7.41-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.41-1.el7.x86_64.rpm
# 至此所有依赖已安装完毕,下面安装客户端和服务端
rpm -ivh mysql-community-client-5.7.41-1.el7.x86_64.rpm
yum -y install net-tools
rpm -ivh mysql-community-server-5.7.41-1.el7.x86_64.rpm
# 查询 MySQL 的安装文件
rpm -qa | grep -i mysql
# yum remove openssl-devel
# yum remove net-tools
问题1
[root@localhost mysql-5.7.41]# rpm -ivh mysql-community-libs-5.7.41-1.el7.x86_64.rpm
警告:mysql-community-libs-5.7.41-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
错误:依赖检测失败:
mysql-community-common(x86-64) >= 5.7.9 被 mysql-community-libs-5.7.41-1.el7.x86_64 需要
mariadb-libs 被 mysql-community-libs-5.7.41-1.el7.x86_64 取代
解决方案1:清除之前安装过的依赖即可,最后重新安装下。
[root@localhost mysql-5.7.41]# yum remove mysql-libs
问题2
[root@localhost mysql-5.7.41]# rpm -ivh mysql-community-server-5.7.41-1.el7.x86_64.rpm
警告:mysql-community-server-5.7.41-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
错误:依赖检测失败:
net-tools 被 mysql-community-server-5.7.41-1.el7.x86_64 需要
解决方案2:
yum -y install net-tools
[root@localhost mysql-5.7.41]# rpm -ivh mysql-community-common-5.7.41-1.el7.x86_64.rpm
警告:mysql-community-common-5.7.41-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-common-5.7.41-1.e################################# [100%]
[root@localhost mysql-5.7.41]#
[root@localhost mysql-5.7.41]# rpm -ivh mysql-community-libs-5.7.41-1.el7.x86_64.rpm
警告:mysql-community-libs-5.7.41-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-libs-5.7.41-1.el7################################# [100%]
[root@localhost mysql-5.7.41]#
[root@localhost mysql-5.7.41]# rpm -ivh mysql-community-libs-compat-5.7.41-1.el7.x86_64.rpm
警告:mysql-community-libs-compat-5.7.41-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-libs-compat-5.7.4################################# [100%]
[root@localhost mysql-5.7.41]#
[root@localhost mysql-5.7.41]# rpm -ivh mysql-community-devel-5.7.41-1.el7.x86_64.rpm
警告:mysql-community-devel-5.7.41-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-devel-5.7.41-1.el################################# [100%]
[root@localhost mysql-5.7.41]#
[root@localhost mysql-5.7.41]# rpm -ivh mysql-community-client-5.7.41-1.el7.x86_64.rpm
警告:mysql-community-client-5.7.41-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-client-5.7.41-1.e################################# [100%]
[root@localhost mysql-5.7.41]#
[root@localhost mysql-5.7.41]# rpm -ivh mysql-community-server-5.7.41-1.el7.x86_64.rpm
警告:mysql-community-server-5.7.41-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID 3a79bd29: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-server-5.7.41-1.e################################# [100%]
# 启动 MySQL 服务
systemctl start mysqld
# 重启 MySQL 服务
systemctl restart mysqld
# 关闭 MySQL 服务
systemctl stop mysqld
#设置开机自启
systemctl enable mysqld
# 查看状态
systemctl status mysqld
rpm 安装 MySQL 会自动生成一个随机密码
cat /var/log/mysqld.log
A temporary password is generated for root@localhost: 2yiNb5Pvum<4
账号:root
随机密码:2yiNb5Pvum<4
# 登录
mysql -u root -p
2yiNb5Pvum<4
# 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Mysql.123456';
# 设置密码的验证强度等级
#Mysql 5.7 版本
# 将密码复杂度校验调整简单类型
# set global validate_password_policy=MEDIUM;
set global validate_password_policy=LOW;
# 设置密码最少位数限制为 4 位
set global validate_password_length=4;
# 查看 mysql 初始的密码策略
SHOW VARIABLES LIKE 'validate_password%';
# 查看 mysql5.7 初始的密码策略
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password_check_user_name | OFF |
| validate_password_dictionary_file | |
| validate_password_length | 8 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | MEDIUM |
| validate_password_special_char_count | 1 |
+--------------------------------------+--------+
自己安装在本地的mysql默认时不允许进行远程登陆,如果想要远程访问本地的数据库需要修改访问权限,将’root‘访问权限修改为’%‘
# 连接服务器
mysql -u root -p
# 看当前所有数据库
show databases;
# 进入mysql数据库
use mysql;
# 查看mysql数据库中所有的表
show tables;
# 执行更新权限语句
# 其中“%”代表所有的地址,意味着所有的地址都可以访问“root”
update user set Host='%' where User='root';
# 查看权限是否修改成功
select host,user from user;
# 刷新服务器配置
FLUSH PRIVILEGES;
# 停止Mysql
systemctl stop mysqld
# 查询 MySQL 的安装文件
rpm -qa | grep -i mysql
# 卸载上述查询的所有安装包
rpm -e mysql-community-libs-5.7.41-1.el7.x86_64 --nodeps
rpm -e mysql-community-devel-5.7.41-1.el7.x86_64 --nodeps
rpm -e mysql-community-common-5.7.41-1.el7.x86_64 --nodeps
rpm -e mysql-community-libs-compat-5.7.41-1.el7.x86_64 --nodeps
rpm -e mysql-community-client-5.7.41-1.el7.x86_64 --nodeps
rpm -e mysql-community-server-5.7.41-1.el7.x86_64 --nodeps
# 再次查询 MySQL 的安装文件
rpm -qa | grep -i mysql
# 删除MySQL的数据存放目录
rm -rf /var/lib/mysql
# 找出服务器中分散的mysql文件夹,查询残留的文件和相关依赖,并删除
find / -name mysql
rm -rf [显示的文件夹路径,每个绝对路径中间用空格隔开]
# 删除mysql日志
rm -rf /var/log/mysqld.log
# 删除MySQL的配置文件备份
rm -rf /etc/my.cnf.rpmsave
# 删除mysql配置文件
rm -rf /etc/my.cnf
rpm -qa | grep mysql
Mysql官网:https://www.mysql.com/
下载网址:https://downloads.mysql.com/archives/community/
cat /etc/redhat-release
首先使用第三方工具上传
# 创建一个文件夹,存放mysql
mkdir -p /usr/mysql
cd /usr/mysql
# 在当前目录下(mysql)下创建一个 mysql-5.7.41 文件夹
mkdir mysql-8.0.34
# 解压安装包到该目录下
tar -xvf mysql-8.0.34-1.el7.x86_64.rpm-bundle.tar -C mysql-8.0.34
[root@localhost mysql-8.0.34]# ls
mysql-community-client-8.0.34-1.el7.x86_64.rpm
mysql-community-debuginfo-8.0.34-1.el7.x86_64.rpm
mysql-community-icu-data-files-8.0.34-1.el7.x86_64.rpm
mysql-community-server-8.0.34-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.34-1.el7.x86_64.rpm
mysql-community-devel-8.0.34-1.el7.x86_64.rpm
mysql-community-libs-8.0.34-1.el7.x86_64.rpm
mysql-community-server-debug-8.0.34-1.el7.x86_64.rpm
mysql-community-common-8.0.34-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.34-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.34-1.el7.x86_64.rpm
mysql-community-test-8.0.34-1.el7.x86_64.rpm
解压后的文件都是 rpm 文件,因此需要用到 rpm 包资源管理器相关的指令安装这些 rpm 的安装包
yum install openssl-devel
安装完该插件之后,依次执行以下命令安装这些 rpm 包
yum install openssl-devel
# yum install net-tools
rpm -ivh mysql-community-common-8.0.34-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.0.34-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.34-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-8.0.34-1.el7.x86_64.rpm
rpm -ivh mysql-community-devel-8.0.34-1.el7.x86_64.rpm
# 至此所有依赖已安装完毕,下面安装客户端和服务端
rpm -ivh mysql-community-client-8.0.34-1.el7.x86_64.rpm
rpm -ivh mysql-community-icu-data-files-8.0.34-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.34-1.el7.x86_64.rpm
# 查询 MySQL 的安装文件
rpm -qa | grep -i mysql
# yum remove openssl-devel
# yum remove net-tools
# 启动 MySQL 服务
systemctl start mysqld
# 重启 MySQL 服务
systemctl restart mysqld
# 关闭 MySQL 服务
systemctl stop mysqld
#设置开机自启
systemctl enable mysqld
# 查看状态
systemctl status mysqld
rpm 安装 MySQL 会自动生成一个随机密码
cat /var/log/mysqld.log
A temporary password is generated for root@localhost: ij9uN+hmchw2
账号:root
随机密码:ij9uN+hmchw2
# 登录
mysql -u root -p
ij9uN+hmchw2
# 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Mysql.123456';
# 设置密码的验证强度等级
#Mysql 8.0 版本
# 将密码复杂度校验调整简单类型
# set global validate_password.policy=MEDIUM;
set global validate_password.policy=LOW;
# 设置密码最少位数限制为 4 位
set global validate_password.length=4;
# 查看 mysql 初始的密码策略
SHOW VARIABLES LIKE 'validate_password%';
mysql> SHOW VARIABLES LIKE 'validate_password%';
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
提示ERROR 1820,让我们先修改密码后才能查看规则。
# 查看 mysql8.0 初始的密码策略
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Mysql.123456';
Query OK, 0 rows affected (0.01 sec)
mysql> SHOW VARIABLES LIKE 'validate_password%';
+-------------------------------------------------+--------+
| Variable_name | Value |
+-------------------------------------------------+--------+
| validate_password.changed_characters_percentage | 0 |
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 8 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | MEDIUM |
| validate_password.special_char_count | 1 |
+-------------------------------------------------+--------+
8 rows in set (0.01 sec)
自己安装在本地的mysql默认时不允许进行远程登陆,如果想要远程访问本地的数据库需要修改访问权限,将’root‘访问权限修改为’%‘
# 连接服务器
mysql -u root -p
# 看当前所有数据库
show databases;
# 进入mysql数据库
use mysql;
# 查看mysql数据库中所有的表
show tables;
# 执行更新权限语句
# 其中“%”代表所有的地址,意味着所有的地址都可以访问“root”
update user set Host='%' where User='root';
# 查看权限是否修改成功
select host,user from user;
# 刷新服务器配置
FLUSH PRIVILEGES;
方法一:
# 登录MySQL后输入
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YourPassword';
FLUSH PRIVILEGES;
方法二:
# 编辑my.cnf文件,更改默认的身份认证插件。
vi /etc/my.cnf
# 在[mysqld]中添加下边的代码
default_authentication_plugin=mysql_native_password
# 然后重启MySQL
service mysqld restart
# 停止Mysql
systemctl stop mysqld
# 查询 MySQL 的安装文件
rpm -qa | grep -i mysql
# 卸载上述查询的所有安装包
rpm -e mysql-community-client-plugins-8.0.34-1.el7.x86_64 --nodeps
rpm -e mysql-community-libs-compat-8.0.34-1.el7.x86_64 --nodeps
rpm -e mysql-community-client-8.0.34-1.el7.x86_64 --nodeps
rpm -e mysql-community-server-8.0.34-1.el7.x86_64 --nodeps
rpm -e mysql-community-common-8.0.34-1.el7.x86_64 --nodeps
rpm -e mysql-community-libs-8.0.34-1.el7.x86_64 --nodeps
rpm -e mysql-community-devel-8.0.34-1.el7.x86_64 --nodeps
rpm -e mysql-community-icu-data-files-8.0.34-1.el7.x86_64 --nodeps
# 再次查询 MySQL 的安装文件
rpm -qa | grep -i mysql
# 找出服务器中分散的mysql文件夹,查询残留的文件和相关依赖,并删除
find / -name mysql
rm -rf [显示的文件夹路径,每个绝对路径中间用空格隔开]
# 删除mysql日志
rm -rf /var/log/mysqld.log
# 删除MySQL的配置文件备份
rm -rf /etc/my.cnf.rpmsave
# 删除mysql配置文件
rm -rf /etc/my.cnf