centos7安装mysql5.7
1.下载依赖包
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
2.安装这些安装包
yum install -y mysql-community-*-5.7.32-1.el7.x86_64.rpm
3.开启服务器并初始化密码
# 开启MySQL服务器
systemctl start mysqld
# 查看默认生成的密码
cat /var/log/mysqld.log | grep password
4.使用默认密码登录
mysql -uroot -h127.0.0.1 -p
5.修改默认密码
# 设置密码等级
set global validate_password_length=6;
set global validate_password_policy=0;
# 修改默认密码,注意替换后面的密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
6.设置 root 账户远程登陆
use `mysql`;
# 注意将密码替换掉
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
FLUSH PRIVILEGES;
设置mysql为不区分大小写
# 通过命令查看mysql是否是区分大小写的
show variables like '%case_table%';
# lower_case_table_names=1(不区分大小写的)
# lower_case_table_names=0(区分大小写)
# 修改lower_case_table_names的值为1
vim /etc/my.cnf;
# 添加
lower_case_table_names=1
# 重启mysql服务
service mysqld restart;
查看mysql的存储引擎
# 看你的mysql现在已提供什么存储引擎:
show engines;
# 看你的mysql当前默认的存储引擎:
show variables like '%storage_engine%';
# 你要看某个表用了什么引擎(在显示结果里参数engine后面的就表示该表当前用的存储引擎):
show create table 表名;
其他:(暂未使用)
现在我们使用 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服务器后再查看
评论区