有个对 MySQL
库数据做测试的需求,因此在 CentOS
下简单安装部署一下,达到灌入数据远程可访问可存取测试的目的。在这里记录一下快速安装配置的流程和命令,话不多说,DDDD。
首先从 Yum 源上安装
wget http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
yum localinstall mysql57-community-release-el7-11.noarch.rpm
安装
yum install mysql-community-server
出错如下
Public key for mysql-community-client-5.7.39-1.el7.x86_64.rpm is not installed
Failing package is: mysql-community-client-5.7.39-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
解决办法,先
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
再次进行服务安装
yum -y install mysql-server
启动服务
systemctl start mysqld
查看 root
用户 密码
grep 'temporary password' /var/log/mysqld.log
记住这个密码,然后登录数据库
mysql -uroot -p
输入上面的密码进入数据库。
先修改一下密码吧,在数据库里执行命令
set password for 'root'@'localhost'=password('密码');
如果密码过于简单,如有缺少字母数字和下划线等,会报错如下。
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
创建用户
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
其中 username
是用户名,host
是可登陆的主机。本地可用 localhost
,任意主机用通配符 %
,password
为密码,可以为空。如
CREATE USER 'root'@'%' IDENTIFIED BY ‘密码’;
授权
GRANT ALL ON *.* TO 'root'@'%';
开启端口
yum install firewalld
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
现在就可以用 Navicat
等工具远程连接访问数据库了。
主要参考了如下博客。
[1]. CentOs安装MySQL
https://www.jianshu.com/p/6b41e0d66f22
[2]. CentOS7安装MySQL(完整版)
https://www.cnblogs.com/yss818824/p/12349719.html
[3]. mysql数据库连接报错:is not allowed to connect to this mysql server
https://blog.csdn.net/weixin_42599091/article/details/125224850
[4]. GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
https://blog.csdn.net/haropy/article/details/123941785
.
.
.
.
.
.
桃花仙人种桃树,又摘桃花换酒钱_