Centos7 安装 mysql5.7 rpm包

1、卸载系统自带的 mariadb-lib


[web@zhangyujie step]$ rpm -qa|grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[web@zhangyujie step]$ sudo rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps

2、下载mysql-5.7.21 rpm安装包,我下载的mysql安装包是mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar下载地址

[web@zhangyujie step]$ wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar

然后解压

[web@zhangyujie step]$ sudo tar -xvf mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar

mysql-community-embedded-devel-5.7.21-1.el7.x86_64.rpm

mysql-community-minimal-debuginfo-5.7.21-1.el7.x86_64.rpm

mysql-community-common-5.7.21-1.el7.x86_64.rpm

mysql-community-libs-compat-5.7.21-1.el7.x86_64.rpm

mysql-community-embedded-compat-5.7.21-1.el7.x86_64.rpm

mysql-community-server-minimal-5.7.21-1.el7.x86_64.rpm

mysql-community-client-5.7.21-1.el7.x86_64.rpm

mysql-community-server-5.7.21-1.el7.x86_64.rpm

mysql-community-embedded-5.7.21-1.el7.x86_64.rpm

mysql-community-test-5.7.21-1.el7.x86_64.rpm

mysql-community-devel-5.7.21-1.el7.x86_64.rpm

mysql-community-libs-5.7.21-1.el7.x86_64.rpm

3、安装
依次执行(几个包有依赖关系,所以执行有先后)下面命令安装

[web@zhangyujie mysql-5.7.21]$ sudo rpm -ivh mysql-community-common-5.7.21-1.el7.x86_64.rpm

[web@zhangyujie mysql-5.7.21]$ sudo rpm -ivh mysql-community-libs-5.7.21-1.el7.x86_64.rpm

[web@zhangyujie mysql-5.7.21]$ sudo rpm -ivh mysql-community-client-5.7.21-1.el7.x86_64.rpm

[web@zhangyujie mysql-5.7.21]$ sudo rpm -ivh mysql-community-server-5.7.21-1.el7.x86_64.rpm

warning: mysql-community-server-5.7.21-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY

error: Failed dependencies:

libnuma.so.1()(64bit) is needed by mysql-community-server-5.7.21-1.el7.x86_64

libnuma.so.1(libnuma_1.1)(64bit) is needed by mysql-community-server-5.7.21-1.el7.x86_64

libnuma.so.1(libnuma_1.2)(64bit) is needed by mysql-community-server-5.7.21-1.el7.x86_64

缺少numactl依赖,

[web@zhangyujie mysql-5.7.21]$ sudo yum install numactl

[web@zhangyujie mysql-5.7.21]$ sudo rpm -ivh mysql-community-server-5.7.21-1.el7.x86_64.rpm

 

在安装rpm -ivh mysql-community-server-5.7.21-1.el7.x86_64.rpm的时候报错如下:

  [root@linux_node_1 src]# rpm -ivh mysql-community-server-5.7.21-1.el7.x86_64.rpm 
  warning: mysql-community-server-5.7.21-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
  error: Failed dependencies:
  libaio.so.1()(64bit) is needed by mysql-community-server-5.7.16-1.el7.x86_64
  libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-5.7.16-1.el7.x86_64
  libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.16-1.el7.x86_64
  net-tools is needed by mysql-community-server-5.7.21-1.el7.x86_64

这个报错的意思是需要安装libaio包和net-tools包:可以yum安装一下,安装 libaio-0.3.107-10.el6.x86_64.rpm,下载地址:

wget http://mirror.centos.org/centos/6/os/x86_64/Packages/libaio-0.3.107-10.el6.x86_64.rpm
然后yum安装net-tools   yum install net-tools  完成之后就可以顺利安装

4. 安装完成后,启动Mysql sudo service mysqld start

5. 查看mysql的初始密码,cat /var/log/mysqld.log |grep password找出文件的内容A temporary password is generated for root@localhost: xxxxxxxxx 冒号后面就是初始密码

6. 进入mysqlmysql -uroot -p 输入初始密码,成功进入mysql

7.重置密码,在mysql的命令行下输入set PASSWORD=PASSWORD('密码'); 注意密码包括大小写数字,而且位数不能太短

============================================================================================================================================

 

mysql 密码强度规则设置

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

1) 查看mysql全局参数配置

该问题其实与mysql的validate_password_policy的值有关。
查看一下msyql密码相关的几个全局参数:

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_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      |  

+--------------------------------------+--------+  

rows in set (0.08 sec)  


2)参数解释

validate_password_dictionary_file
插件用于验证密码强度的字典文件路径。

validate_password_length
密码最小长度,参数默认为8,它有最小值的限制,最小值为:validate_password_number_count + validate_password_special_char_count + (2 * validate_password_mixed_case_count)

validate_password_mixed_case_count
密码至少要包含的小写字母个数和大写字母个数。

validate_password_number_count
密码至少要包含的数字个数。

validate_password_policy
密码强度检查等级,0/LOW、1/MEDIUM、2/STRONG。有以下取值:
Policy                 Tests Performed                                                                                                        
0 or LOW               Length                                                                                                                      
1 or MEDIUM         Length; numeric, lowercase/uppercase, and special characters                             
2 or STRONG        Length; numeric, lowercase/uppercase, and special characters; dictionary file      
默认是1,即MEDIUM,所以刚开始设置的密码必须符合长度,且必须含有数字,小写或大写字母,特殊字符。

validate_password_special_char_count
密码至少要包含的特殊字符数。

 

3)修改mysql参数配置

mysql> set global validate_password_policy=0;  

Query OK, 0 rows affected (0.05 sec)  

  

mysql>   

mysql>   

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_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     |  

+--------------------------------------+-------+  

rows in set (0.00 sec)  

 

4)修改简单密码:

mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123');  

Query OK, 0 rows affected, 1 warning (0.00 sec)  

 

OK了,完美解决!

 

============================================================================================================================================

开启MySQL远程访问权限 允许远程连接

1、登陆mysql数据库    

   mysql -u root -p

   查看user表

mysql> use mysql;
Database changed
mysql> select host,user,password from user;
+--------------+------+-------------------------------------------+
| host         | user | password                                  |
+--------------+------+-------------------------------------------+
| localhost    | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
| 192.168.1.1 | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
+--------------+------+-------------------------------------------+
2 rows in set (0.00 sec)

 

   可以看到在user表中已创建的root用户。host字段表示登录的主机,其值可以用IP,也可用主机名,

   (1)有时想用本地IP登录,那么可以将以上的Host值改为自己的Ip即可。

2、实现远程连接(授权法)

   将host字段的值改为%就表示在任何客户端机器上能以root用户登录到mysql服务器,建议在开发时设为%。   
   update user set host = ’%’ where user = ’root’;

   将权限改为ALL PRIVILEGES

mysql> use mysql;
Database changed
mysql> grant all privileges  on *.* to root@'%' identified by "password";
Query OK, 0 rows affected (0.00 sec)

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

mysql> select host,user,password from user;
+--------------+------+-------------------------------------------+
| host         | user | password                                  |
+--------------+------+-------------------------------------------+
| localhost    | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
| 192.168.1.1 | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
| %            | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
+--------------+------+-------------------------------------------+
3 rows in set (0.00 sec)

这样机器就可以以用户名root密码root远程访问该机器上的MySql.

3、实现远程连接(改表法)

use mysql;

update user set host = '%' where user = 'root';

这样在远端就可以通过root用户访问Mysql.

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值