简述在centos7环境下安装mysql的过程,主要就是修改默认密码并开启远程权限这一步,这样方便远程连接进行读写。以下是详细过程:
- 下载mysql资源
wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
- 进行repo安装
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
- 使用yum命令即可完成安装
yum install mysql-server
systemctl start mysqld #启动MySQL
#如果提示类似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
修改mysql密码,首先以root登录,提示输入密码直接跳过即可
[root@VM_0_14_centos home]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.28
mysql> set password=password("你的密码");
Query OK, 0 rows affected, 1 warning (0.00 sec)
# 执行flush privileges后才生效
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql>
再次安装时发现密码不能直接跳过,解决方法如下:
# 查看mysql临时密码
grep 'temporary password' /var/log/mysqld.log
# 登录后修改安全等级
set global validate_password_policy=LOW;
# alter修改密码(也可以set password)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
- 接着就是远程登录授权
# 模板:
grant all privileges on 库名.表名 to '用户名'@'IP地址' identified by '密码' with grant option;
flush privileges;
# *.*表示所有数据库和表 'root'@'%'表示不限制登录用户的ip