【Mysql】Linux RPM 方式安装 MySQL

本文详细介绍了在Linux环境下,通过RPM方式安装MySQL的步骤,包括检查与卸载旧版本、下载安装包、设置初始密码、重置数据库密码、解决密码策略问题以及开启远程登录权限。
摘要由CSDN通过智能技术生成

Linux RPM 方式安装 MySQL

(记得使用 root 账户进行操作,若使用普通用户,那么请修改相应文件夹权限)

1 检查以前是否有安装Mysql,卸载

  1. 检查以前是否装过 MySQL

    rpm -qa|grep -i mysql
    

    centos7默认会安装mariadb,也要卸载,避免冲突

    [root@hdp01 ~]# rpm -qa |grep -i mariadb
    mariadb-libs-5.5.60-1.el7_5.x86_64
    [root@hdp01 ~]# rpm -e --nodeps mariadb-libs
    
  2. 发现有的话就都卸载
    在这里插入图片描述

  3. 删除老版本 mysql 的开发头文件和库

    rm -fr /usr/lib/mysql #数据库目录
    rm -fr /usr/include/mysql
    rm -f /etc/my.cnf
    rm -fr /var/lib/mysql
    
    

注意:卸载后/var/lib/mysql 中的数据及/etc/my.cnf 不会删除,确定没用后就手工删除

2 下载安装包

https://dev.mysql.com/downloads/mysql/5.6.html#downloads
在这里插入图片描述
但是官网下载太慢了,我们还是从清华镜像下载

[root@hdp01 apps]# wget https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-5.7.25-1.el7.x86_64.rpm-bundle.tar
[root@hdp01 apps]# tar -xvf mysql-5.7.25-1.el7.x86_64.rpm-bundle.tar 
mysql-community-libs-5.7.25-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.25-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.25-1.el7.x86_64.rpm
mysql-community-embedded-5.7.25-1.el7.x86_64.rpm
mysql-community-client-5.7.25-1.el7.x86_64.rpm
mysql-community-server-5.7.25-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.25-1.el7.x86_64.rpm
mysql-community-test-5.7.25-1.el7.x86_64.rpm
mysql-community-devel-5.7.25-1.el7.x86_64.rpm
mysql-community-common-5.7.25-1.el7.x86_64.rpm

3 开始安装

在这里插入图片描述

[root@hdp01 mysql-rpm]# rpm -ivh mysql-community-common-5.7.25-1.el7.x86_64.rpm 
[root@hdp01 mysql-rpm]# rpm -ivh mysql-community-libs-5.7.25-1.el7.x86_64.rpm 
[root@hdp01 mysql-rpm]# rpm -ivh mysql-community-client-5.7.25-1.el7.x86_64.rpm 
[root@hdp01 mysql-rpm]# rpm -ivh mysql-community-server-5.7.25-1.el7.x86_64.rpm 

找到初始密码
vi /var/log/mysqld.log
2019-12-29T12:39:26.213233Z 1 [Note] A temporary password is generated for root@localhost: !%;foq4hiKT4

如果找不到这个密码文件,就用下面方式重置

4 重置数据库密码

编辑my.cnf允许空密码登录

vi /etc/my.cnf
#在[mysqld]下添加
skip-grant-tables=1

重新启动Mysql服务
使用Root登录数据库、使用mysql数据库、修改root密码、退出数据库

[root@hdp01 etc]# systemctl restart mysqld.service
[root@hdp01 etc]# mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.25 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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.

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

Database changed
mysql> update user set authentication_string=password('123456'),password_last_changed=now() where user='root';
Query OK, 1 row affected, 1 warning (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> exit
Bye

再次打开my.cnf,将skip-grant-tables=1删掉,保存退出
重启mysql服务
再次试验登录OK

[root@hdp01 etc]# 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.25

Copyright (c) 2000, 2019, 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.

mysql> 

5 修改mysql密码过期问题(无则跳过)

登录发现无论执行什么命令都报错:

mysql> show datables;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'datables' at line 1

查看过期

mysql> select host,user,authentication_string,password_expired from user;
+-----------+---------------+-------------------------------------------+------------------+
| host      | user          | authentication_string                     | password_expired |
+-----------+---------------+-------------------------------------------+------------------+
| localhost | root          | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | Y                |
| localhost | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | N                |
| localhost | mysql.sys     | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | N                |
+-----------+---------------+-------------------------------------------+------------------+
3 rows in set (0.00 sec)

修改过期

mysql> update user set password_expired='N' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

6 解决Your password does not satisfy the current policy requirements

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; 
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

原因:

原来MySQL5.6.6版本之后增加了密码强度验证插件validate_password,相关参数设置的较为严格。
使用了该插件会检查设置的密码是否符合当前设置的强度规则,若不满足则拒绝设置。影响的语句和函数有:create user,grant,set password,password(),old password。

解决办法:

  1. 查看全局参数

    mysql> select @@validate_password_policy; 
    +----------------------------+
    | @@validate_password_policy |
    +----------------------------+
    | MEDIUM                     |
    +----------------------------+
    1 row in set (0.00 sec)
    
    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      |
    +--------------------------------------+--------+
    7 rows in set (0.00 sec)
    
    
  2. 参数解释

    参数解释
    validate_password_dictionary_file插件用于验证密码强度的字典文件路径
    alidate_password_length密码最小长度,参数默认为8,它有最小值的限制,最小值为:validate_password_number_count + validate_password_special_char_count + (2 * validate_password_mixed_case_count)
    alidate_password_mixed_case_count密码至少要包含的小写字母个数和大写字母个数。
    alidate_password_number_count密码至少要包含的数字个数。
    alidate_password_policy密码强度检查等级,0/LOW、1/MEDIUM、2/STRONG。
    alidate_password_special_char_count密码至少要包含的特殊字符数。

    在这里插入图片描述

  3. 修改配置

mysql> set global validate_password_policy=0;  
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_mixed_case_count=0;  
Query OK, 0 rows affected (0.00 sec)

mysql>  set global validate_password_number_count=3;  
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_special_char_count=0;  
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_length=3;  
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW VARIABLES LIKE 'validate_password%';  
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password_check_user_name    | OFF   |
| validate_password_dictionary_file    |       |
| validate_password_length             | 3     |
| validate_password_mixed_case_count   | 0     |
| validate_password_number_count       | 3     |
| validate_password_policy             | LOW   |
| validate_password_special_char_count | 0     |
+--------------------------------------+-------+
7 rows in set (0.00 sec)

7 增加远程登陆权限

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; 
Query OK, 0 rows affected, 1 warning (0.00 sec)

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux安装MySQL的常见方式有几种。一种是使用编译好的安装包,比如使用rpm安装包进行安装,如mysql57-community-release-el7-10.noarch.rpm。另一种是使用源码包进行安装,一般是.tar.gz格式的文件。还有一种是在线安装,可以使用YUM或APT等工具进行安装,比如使用yum命令进行安装,如yum -y install mysql-server。你可以在mysql的官网上找到相对应版本的下载地址,比如https://dev.mysql.com/downloads/mysql/5.6.html#downloads。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Linux安装Mysqlrpm安装)](https://blog.csdn.net/weixin_50367873/article/details/121975384)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [Linux安装mysql5.7.25,rpm安装方式保姆级教程!](https://blog.csdn.net/weixin_58428691/article/details/128427085)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Linux系统安装mysqlrpm方式安装)](https://blog.csdn.net/qq_45165744/article/details/124285828)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值