linux CentOS7 yum安装 MySQL8

本文详细介绍了在CentOS7系统中如何使用yum安装MySQL8,包括检查系统版本、获取mysql yum repository链接、安装MySQL、启动服务、设置密码、创建用户以及修改配置文件的步骤。
摘要由CSDN通过智能技术生成
安装 MySQL

查看系统版本(输出结果会看到 CentOS Linux 7 (Core)

cat /etc/os-release

获取 mysql yum repository 链接:https://dev.mysql.com/downloads/repo/yum/

cd /usr/local/src/
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

安装源:

yum -y install mysql80-community-release-el7-3.noarch.rpm

以下为检测安装源及输出信息:

yum repolist enabled | grep "mysql.*-community.*"

mysql-connectors-community/x86_64 MySQL Connectors Community      131
mysql-tools-community/x86_64      MySQL Tools Community           100
mysql80-community/x86_64          MySQL 8.0 Community Server      145

安装 MySQL

yum -y install mysql-community-server

安装完成将显示如下信息:

Installed:
  mysql-community-libs.x86_64 0:8.0.18-1.el7           mysql-community-libs-compat.x86_64 0:8.0.18-1.el7        
  mysql-community-server.x86_64 0:8.0.18-1.el7        

Dependency Installed:
  libaio.x86_64 0:0.3.109-13.el7                         mysql-community-client.x86_64 0:8.0.18-1.el7          
  mysql-community-common.x86_64 0:8.0.18-1.el7          

Replaced:
  mariadb-libs.x86_64 1:5.5.60-1.el7_5                                                                          

Complete!

安装完成

安装成功后

启动 mysql 等操作

service mysqld start
service mysqld status
service mysqld stop
service mysqld restart

systemctl start mysqld.service
systemctl status mysqld.service
systemctl stop mysqld.service
systemctl restart mysqld.service

获取密码:

grep "password" /var/log/mysqld.log
... password is generated for root@localhost: %isC&hkru0v0

登录:

mysql -uroot -p

修改密码:

alter user root@localhost identified by 'password';

创建用户:

use mysql;
create user 'root'@'%' identified by 'password';
grant all privileges on *.* to 'root'@'%';
flush privileges;

通过Navicat等工具连接失败,更改加密规则

# 修改加密规则
alter user 'root'@'%' identified by 'password' password expire never;
# 更新密码
alter user 'root'@'%' identified with mysql_native_password by 'password';
修改配置

查看使用的配置文件(当前默认无)

ps aux|grep mysql|grep 'my.cnf'

MySQL 默认会搜寻 my.cnf 的目录,顺序排前的优先,
查找 my.cnf ,只存在 /etc/my.cnf

mysql --help|grep 'my.cnf'
                      order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf

查看字符集配置

show variables where Variable_name like 'character%' or Variable_name like 'collation%';

/etc/my.cnf 添加如下内容,完成后重启 MySQL

[client] 
default-character-set = utf8mb4 
[mysql] 
default-character-set = utf8mb4 
[mysqld] 
character-set-client-handshake = FALSE 
character-set-server = utf8mb4 
collation-server = utf8mb4_unicode_ci 
init_connect='SET NAMES utf8mb4'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值