redhat 5.8安装mysql_redhat上安装MySQL5.7.12

本文档详细介绍了在Linux系统中下载、安装、配置MySQL 5.7的过程,包括检查是否已安装MySQL、卸载旧版本、安装MySQL组件、启动服务、设置初始密码、修改配置文件、调整密码策略、开启远程访问以及处理乱码问题。此外,还涉及到了防火墙的管理,确保MySQL服务能够正常运行并接受远程连接。
摘要由CSDN通过智能技术生成

0.下载mysql

wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar

1.查找是否安装

[root@mysql opt]# rpm -qa|grep mysql

查找是否安装mysql,结果如下

mysql-libs-5.1.73-3.el6_5.x86_64

[root@mysql opt]# rpm -e --nodeps mysql-libs-5.1.73-3.el6_5.x86_64

卸载mysql

[root@cmos1 mysql]# rpm -qa | grep mysql

mysql-libs-5.1.73-3.el6_5.x86_64

[root@cmos1 mysql]# rpm -e --nodeps mysql-libs-5.1.73-3.el6_5.x86_64

[root@cmos1 mysql]# rpm -qa | grep mysql

[root@cmos1 mysql]#

2. 解压

tar -xf mysql-5.7.12-1.el6.x86_64.rpm-bundle.tar

解压完成后由这么几个文件:

mysql-community-client-5.7.12-1.el6.x86_64.rpm

mysql-community-common-5.7.12-1.el6.x86_64.rpm

mysql-community-devel-5.7.12-1.el6.x86_64.rpm

mysql-community-embedded-5.7.12-1.el6.x86_64.rpm

mysql-community-embedded-devel-5.7.12-1.el6.x86_64.rpm

mysql-community-libs-5.7.12-1.el6.x86_64.rpm

mysql-community-libs-compat-5.7.12-1.el6.x86_64.rpm

mysql-community-server-5.7.12-1.el6.x86_64.rpm

mysql-community-test-5.7.12-1.el6.x86_64.rpm

3.开始安装

根据需要安装:

mysql-community-client-5.7.12-1.el6.x86_64.rpm

mysql-community-common-5.7.12-1.el6.x86_64.rpm

mysql-community-libs-5.7.12-1.el6.x86_64.rpm

mysql-community-server-5.7.12-1.el6.x86_64.rpm

mysql-community-devel-5.7.12-1.el6.x86_64.rpm

执行安装的示例:

rpm -ivh mysql-community-common-5.7.12-1.el6.x86_64.rpm

rpm -ivh mysql-community-libs-5.7.12-1.el6.x86_64.rpm

rpm -ivh mysql-community-devel-5.7.12-1.el6.x86_64.rpm

rpm -ivh mysql-community-client-5.7.12-1.el6.x86_64.rpm

rpm -ivh mysql-community-server-5.7.12-1.el6.x86_64.rpm

过程如下:

[root@cmos1 mysql]# rpm -ivh mysql-community-common-5.7.12-1.el6.x86_64.rpm

warning: mysql-community-common-5.7.12-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY

Preparing... ########################################### [100%]

1:mysql-community-common ########################################### [100%]

[root@cmos1 mysql]# rpm -ivh mysql-community-libs-5.7.12-1.el6.x86_64.rpm

warning: mysql-community-libs-5.7.12-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY

Preparing... ########################################### [100%]

1:mysql-community-libs ########################################### [100%]

[root@cmos1 mysql]# rpm -ivh mysql-community-devel-5.7.12-1.el6.x86_64.rpm

warning: mysql-community-devel-5.7.12-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY

Preparing... ########################################### [100%]

1:mysql-community-devel ########################################### [100%]

[root@cmos1 mysql]# rpm -ivh mysql-community-client-5.7.12-1.el6.x86_64.rpm

warning: mysql-community-client-5.7.12-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY

Preparing... ########################################### [100%]

1:mysql-community-client ########################################### [100%]

[root@cmos1 mysql]# rpm -ivh mysql-community-server-5.7.12-1.el6.x86_64.rpm

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

Preparing... ########################################### [100%]

1:mysql-community-server ########################################### [100%]

[root@cmos1 mysql]#

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

不要

4.启动mysql

service mysql start

或者使用如下命令:

/etc/init.d/mysql start

5. 此处没有设置密码,会报错

#1045 - Access denied for user 'root'@'localhost' (using password: NO)

解决方法是用安全方式登录,修改密码即可。

4.mysql安全方式启动:

mysqld_safe --user=mysql --skip-grant-tabes --skip-networking &

由于mysql5.7 中mysql.user 表中没有Password字段,用authentication_string 代替即可。

6. 至此mysql安装完成,可用客户端工具连接使用了.

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

4.修改配置,跳过密码检测

[root@mysql MySQL]#vi /etc/my.cnf

修改配置文件

加入 skip-grant-tables

跳过密码检测

5.启动mysql

[root@mysql MySQL]#service mysqld start

启动mysql,过程如下:

[root@cmos1 mysql]# service mysqld start

Initializing MySQL database: [ OK ]

Installing validate password plugin: [ OK ]

Starting mysqld: [ OK ]

[root@cmos1 mysql]#

[root@mysql MySQL]#mysql –u root –p

登录,无需密码直接回车

过程如下:

[root@cmos1 mysql]# 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.12 MySQL Community Server (GPL)

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

7.设置密码

mysql>use mysql;

选择数据库

mysql>update user set password_expired="N" where user="root";

设置密码失效为”N”

mysql>update user set authentication_string=password("123456") where user="root";

设置密码为”123456”

mysql>flush privileges;

刷新生效

mysql>quit;

退出

8.修改配置,恢复密码检测

[root@mysql MySQL]#vi /etc/my.cnf

修改配置

注释或删除 #skip-grant-tables

9.用密码登录

[root@mysql MySQL]#mysql –u root –p

用新密码登陆

10.修改密码

[root@mysql MySQL]#mysqladmin -u用户名 -p旧密码 password 新密码

[root@mysql MySQL]#mysqladmin -uroot –p123456 password “123-abcABC“

mysql>set password=password("123456");

11.查看现有的密码策略

mysql>show variables like 'val%';

validate_password_dictionary_file参数是指定密码验证的字典文件路径。

validate_password_length参数是密码的长度,这个参数由下面的公式生成

validate_password_number_count+ validate_password_special_char_count+ (2 * validate_password_mixed_case_count)

validate_password_mixed_case_count参数是密码中英文字符大小写的个数,当密码策略是MEDIUM或以上时生效。

validate_password_number_count参数是密码中至少含有的数字个数,当密码策略是MEDIUM或以上时生效。

validate_password_policy这个参数可以设为0、1、2,分别代表从低到高的密码强度,此参数的默认值为1,如果想将密码强度改若,则更改此参数为0。

validate_password_special_char_count参数是密码中非英文数字等特殊字符的个数,当密码策略是MEDIUM或以上时生效。

12.更改密码策略

mysql> set global validate_password_length=0; --更改密码长度

mysql> set global validate_password_policy=0; --更改密码策略为LOW

13.允许mysql远程访问

赋予任何主机访问数据的权限

mysql>grant all privileges on *.* to 'root'@'%'with grant option;

会报错:ERROR 1133 (42000): Can't find any matching row in the user table

其实如果事先在mysql.user表中存在root用户就正常了,或,将这句末尾加上identified by '密码' 也就正常了。如下面的命令行

mysql>grant all privileges on *.* to 'root'@'%'identified by '123456' with grant option;

14.设置编码,解决乱码问题

default-character-set=utf-8

通过在/etc/my.cnf中增加参数default-character-set=utf-8解决乱码问题

15.查看防火墙状态

systemctl status firewalld

临时关闭防火墙命令。重启电脑后,防火墙自动起来

systemctl stop firewalld

永久关闭防火墙命令。重启后,防火墙不会自动启动

systemctl disable firewalld

打开防火墙命令systemctl enable firewalld

16.mysql默认已是开机自启动

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值