centos安装mysql5.7(2022年更新)

文章目录

        • 安装步骤
        • 登陆root账号
        • 添加账号(可选)
        • 提供远程访问(可选)
        • 参考

本文主要介绍centos环境下如何安装mysql。包括:安装步骤、账号登陆、添加账号、远程访问4个部分。

安装步骤

依次执行以下命令安装:

//打开mysql仓库
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
rpm -Uvh  https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
sudo yum -y install mysql-community-server
rpm -qa|grep mysql

安装成功后,最后显示:

rpm -qa|grep mysql
mysql-community-common-5.7.39-1.el7.x86_64
mysql-community-client-5.7.39-1.el7.x86_64
mysql57-community-release-el7-9.noarch
mysql-community-libs-5.7.39-1.el7.x86_64
mysql-community-server-5.7.39-1.el7.x86_64

可能遇到的问题:

问题1

The GPG keys listed for the “MySQL 5.7 Community Server” repository are already installed but they are not correct for this package

解决办法:执行第一条命令rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022可解决。

问题2

No match for argument: mysql-community-server
Error: Unable to find a match: mysql-community-server

解决办法:
先执行:yum module disable mysql
再执行:yum -y install mysql-community-server

安装成功后启动mysql,mysql会创建一个root账号并分配一个初始密码。

//启动
systemctl start mysqld
//启动后保存root密码
grep 'A temporary password' /var/log/mysqld.log |tail -1 
登陆root账号

首次以root账号登陆后,需要修改root密码才能继续操作。
注意此时mysql设置的密码校验是高要求的,需要设置为12位包含大小写、数字、符号才能通过。

例如:
set password for root@localhost = password('Le98jfcVoc!X');

如果在测试环境希望降低密码校验等级,可以通过设置全局变量进行修改。
show variables like ‘%validate_password%’;
SET GLOBAL validate_password_policy = LOW;

mysql> show variables like '%validate_password%';
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| validate_password_check_user_name    | OFF   |
| validate_password_dictionary_file    |       |
| validate_password_length             | 6     |
| validate_password_mixed_case_count   | 1     |
| validate_password_number_count       | 0     |
| validate_password_policy             | LOW   |
| validate_password_special_char_count | 1     |
+--------------------------------------+-------+
7 rows in set (0.00 sec)
添加账号(可选)

以下演示设置一个低校验的账号,限测试环境使用,在生产环境时请选择校验严格的方式。

create user “test” identified by “123456”;
grant all privileges on . to ‘test’@‘%’ identified by ‘123456’ ;

提供远程访问(可选)

提供远程访问时,首先mysql账号的Host需要开放IP访问。见mysql库的user表。其次需要服务器的端口需要支持远程访问,需要通过防火墙设置。

firewall-cmd --state
systemctl start firewalld
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
firewall-cmd --zone=public --list-ports
systemctl stop firewalld

设置后可以通过本机远程连接mysql服务器。

参考

How to Install MySQL 5.7 on CentOS 7 & Fedora 36/35:https://tecadmin.net/install-mysql-5-7-centos-rhel/
报错解决1:https://blog.csdn.net/zhaokuo719/article/details/105508321
报错解决2:https://exerror.com/the-gpg-keys-listed-for-the-mysql-5-7-community-server-repository-are-already-installed-but-they-are-not-correct-for-this-package/
设置密码:https://blog.csdn.net/qq_33285112/article/details/78982766
修改隐私等级:https://stackoverflow.com/questions/43094726/your-password-does-not-satisfy-the-current-policy-requirements
阿里云轻量服务器开启防火墙访问:https://blog.csdn.net/Amador/article/details/115431207#comments_19310615

你可能感兴趣的:(快速上手,centos,mysql,数据库)