# 注意事项 {#注意事项}
- 本次使用的是
CentOS7
+MySQL 5.7.32
其他版本的 5.7 MySQL 应该也支持 - 本次不提供安装包,但提供安装包的下载地址,均为官网下载地址
- 如果报出权限不足的异常请在涉及到的命令前面加上
sudo
,如果无法解决请联系系统管理员分配权限
# 安装步骤 {#安装步骤}
-
去官网下载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
为了方便,来下载页面描述一下我们下载了那些 rpm
- 把他们下载到 CentOS 的
/usr/local/src
目录下,如图显示
-
然后安装这些安装包,注意有依赖,需要联网 使用命令:
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 '您的密码';
我们退出后发现密码已经设置完成
-
设置 root 账户远程登陆(此步骤如果不需要可以跳过),进入到 MySQL 命令行使用命令:
use
mysql
;注意将密码替换掉
GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY '您的密码' WITH GRANT OPTION; FLUSH PRIVILEGES;
注意开放 3306
端口之后在 window 上远程连接可以成功:
- 现在我们使用
show variables like 'character%';
命令查看字符集看到一些字符集默认还是拉丁文,我们需要将他们改成UTF-8
:
我们修改 /etc/my.cnf
文件来修改这个配置,使用命令:
vim /etc/my.cnf
修改之后:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
character-set-server=utf8
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
重点注意修改部分:
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
character-set-server=utf8
使用命令 systemctl restart mysqld
重启MySQL服务器后再查看:
原文地址:https://blog.csdn.net/m0_51510236/article/details/113791490