美文网首页MySQL
Linux CentOS 7.8安装MySQL5.7

Linux CentOS 7.8安装MySQL5.7

作者: 青山淼淼 | 来源:发表于2020-07-28 21:31 被阅读0次

CentOS和MySQL

  • CentOS Linux release 7.8.2003 (Core)
  • MySQL 5.7

1.安装MySQL源

# 下载
bash > wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
# 安装 MySQL 源
bash > yum localinstall mysql57-community-release-el7-11.noarch.rpm

2.检查源是否安装成功

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

页面输出信息表示源安装成功

mysql-connectors-community/x86_64 MySQL Connectors Community                 165
mysql-tools-community/x86_64      MySQL Tools Community                      115
mysql57-community/x86_64          MySQL 5.7 Community Server                 444

3.使用yum install 命令安装MySQL

bash > yum install -y mysql-community-server

4.启动MySQL服务

CentOs7 下 启动/关闭/重启服务的命令是 systemctl start|stop|restart

bash > systemctl start mysqld

systemctl status 命令查看服务运行状态

bash > systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 二 2020-07-28 21:09:44 CST; 57s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 25677 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 25628 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 25681 (mysqld)
CGroup: /system.slice/mysqld.service
└─25681 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

7月 28 21:09:38 iZm5ebq5g3dxxmygidjc5cZ systemd[1]: Starting MySQL Server...
7月 28 21:09:44 iZm5ebq5g3dxxmygidjc5cZ systemd[1]: Started MySQL Server.

这里可看到MySQL 运行的状态 active (running)

5.设置开机启动MySQL 服务

bash > systemctl enable mysqld
# 重载所有修改过的配置文件
bash > systemctl daemon-reload

重启ContOs 服务器测试.(没有问题)

6.查看MySQL默认密码

MySQL 安装完成之后,生成的默认密码在 /var/log/mysqld.log 文件中。使用 grep 命令找到日志中的密码。

bash > grep 'temporary password' /var/log/mysqld.log
查看初始密码

7.首次通过初始密码登录后,使用以下命令修改密码

bash > mysql -u root -p
#输入密码 
#执行修改密码语句.
bash > ALTER USER 'root'@'localhost' IDENTIFIED BY 'Vine@yyy1';

8.添加一个用于远程连接的账号,如Navicat

bash > GRANT ALL PRIVILEGES ON *.* TO 'xianglin'@'%' IDENTIFIED BY 'Xiang@lin!1996' WITH GRANT OPTION;
#Query OK, 0 rows affected, 1 warning (0.00 sec) 

9.设置默认编码为 utf8

MySQL 安装后默认不支持中文,需要修改编码。

现在查看编码:

mysql> show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

修改 /etc/my.cnf 配置文件,在相关节点(没有则自行添加)下添加编码配置,如下:

[mysqld]
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8

保存之后使用systemctl restart mysqld 查看编码。

mysql> show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

默认配置文件路径:

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

转自 lancely CentOS 7 下 MySQL 5.7 的安装与配置

相关文章

网友评论

    本文标题:Linux CentOS 7.8安装MySQL5.7

    本文链接:https://www.haomeiwen.com/subject/qlvqrktx.html