目录
suibi

centos安装MySQL步骤详解(centos7数据库安装命令)


mysql通过yum实现安装

先去官网下载rpm包,使用命令

wget \
https://cdn.mysql.com/archives/mysql-5.7/mysql-community-client-5.7.32-1.el7.x86_64.rpm \
https://cdn.mysql.com/archives/mysql-5.7/mysql-community-common-5.7.32-1.el7.x86_64.rpm \
https://cdn.mysql.com/archives/mysql-5.7/mysql-community-libs-5.7.32-1.el7.x86_64.rpm \
https://cdn.mysql.com/archives/mysql-5.7/mysql-community-libs-compat-5.7.32-1.el7.x86_64.rpm \
https://cdn.mysql.com/archives/mysql-5.7/mysql-community-server-5.7.32-1.el7.x86_64.rpm

然后安装这些安装包,注意有依赖,需要联网使用命令:

yum install -y mysql-community-*-5.7.32-1.el7.x86_64.rpm

开启服务器并初始化密码,使用的命令和命令详解

# 开启MySQL服务器
systemctl start mysqld
# 查看默认生成的密码
cat /var/log/mysqld.log | grep password

使用该密码登录本地 MySQL 服务器,使用命令:

mysql -uroot -h127.0.0.1 -p

然后输入以下命令修改默认密码:

# 设置密码等级
set global validate_password_length=4;
set global validate_password_policy=0;
# 修改默认密码,注意替换后面的密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '您的密码';

使用修改好的密码登录mysql,授权

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '您的密码' WITH GRANT OPTION;
FLUSH PRIVILEGES;

使用 show variables like 'character%'; 命令查看字符集看到一些字符集默认还是拉丁文,我们需要将它们 UTF-8:

  • 编辑/etc/my.cnf文件
vim /etc/my.cnf
  • 将下边代码复制到my.cnf文件中
[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysqld]
character-set-server=utf8

保存退出后重启mysql

systemctl restart mysqld

亲测可用


写笔记

咨询

您的电子邮箱地址不会被公开。