Gadzan

CentOS7安装MySQL5.7

在MySQL官网查看yum源安装包地址

# 下载mysql源安装包
wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# 安装mysql源
yum localinstall mysql57-community-release-el7-8.noarch.rpm
# 查看源是否安装成功
yum repolist enabled | grep "mysql.*-community.*"

查看源是否安装成功

# 安装MySQL
yum install mysql-community-server
# 启动MySQL
systemctl start mysqld
# 查看MySQL运行状态
systemctl status mysqld
# 设置开机启动
systemctl enable mysqld
systemctl daemon-reload

mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:

# 查看默认密码
grep 'temporary password' /var/log/mysqld.log
# 连接MySQL
mysql -u root -p
# 改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass1!';
# 或者
set password for 'root'@'localhost'=password('MyNewPass4!');

默认配置文件路径:
配置文件:/etc/my.cnf
日志文件:/var/log//var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket文件:/var/run/mysqld/mysqld.pid

客户端提供MYSQL的环境,但是不支持中文,通过以下命令可以查看mysql的字符集

show variables like 'character_set%';

为了让 MySQL支持中文,需要把字符集改成UTF-8,方法如下

# vim /etc/mycnf

改成如下内容

[client]
port=3306
socket=/var/lib/mysql/mysql.sock
default-character-set=utf8

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
character-set-server=utf8

[mysql]
no-auto-rehash
default-character-set=utf8

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# 重启MySQL
service mysql restart
# 查看编码,可以看到都变成utf-8了
show variables like 'character_set%';

知识共享许可协议 本作品采用知识共享署名 4.0 国际许可协议进行许可。

评论

评论加载中...