CentOS使用yum在线安装mysql5.7
1.安装wget
yum install -y wget
2.CentOS 6.5与CentOS 7由于对MySQL操作权限不同,安装步骤略有不同
2.1 CentOS 6.5 下载并安装MySQL官方的 Yum Repository
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server
2.2CentOS 7下安装MySQL
2.2.1 wget获取mysql 5.7
wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
2.2.2 yum安装mysql 5.7
yum -y install mysql57-community-release-el7-10.noarch.rpm
2.2.3 yum安装mysql-community-server
yum -y install mysql-community-server
报如下错误:
Public key for mysql-community-common-5.7.38-1.el7.x86_64.rpm is not installed
Failing package is: mysql-community-common-5.7.38-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
这是由于MySQL GPG 密钥已过期导致的
需要运行命令, 以2022年为例
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
2.2.4 yum重新安装mysql-community-server
yum -y install mysql-community-server
yum安装MySQL服务结束!
3.MySQL数据库设置
#启动MySQL
systemctl start mysqld.service
#查看MySQL运行状态
systemctl status mysqld.service
4.在日志文件中找出密码
grep "password" /var/log/mysqld.log
5.进入数据库
mysql -uroot -p # 回车后会提示输入密码
6.设置mysql密码
6.1修改变更,便于修改简单密码
set global validate_password_policy=0;
set global validate_password_length=1;
6.2修改密码
--修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
6.3远程授权,便于使用navicat等远程客户端连接
--远程授权
grant all on *.* to root@'%' identified by 'root';
7.移除Yum Repository
yum -y remove mysql57-community-release-el7-10.noarch
8.登录测试
mysql -uroot -pSimple@123
9mysql简单应用
9.1mysql创建数据库,指定编码格式
create database MyDB_two character set utf8;
9.2创建表
create table MyDB_two.tb_user(
id int(10) PRIMARY KEY AUTO_INCREMENT,
user_name varchar(20),
password varchar(20),
name varchar(20),
age int(10),
sex int(10),
birthday date,
created date,
updated date
)character set utf8 collate utf8_general_ci;
9.3数据插入
insert into MyDB_two.tb_user(id,user_name,password,name,age,sex,birthday,created,updated)
values(1,'zhangsan','Simple@1234','张三',20,1,'2001-01-01','2021-08-07','2021-09-10');
9.4查询结果
CentOS 7 安装mysql参考链接
https://www.cnblogs.com/ag-chen/p/16004311.html
https://blog.youkuaiyun.com/wenbingping/article/details/122637007
https://blog.youkuaiyun.com/wenbingping/article/details/122634416