CentOS 7.7下Yum安装MySQL5.7
【摘要】 CentOS 7.7下Yum安装MySQL5.7
部署环境
- CentOS 7.7 64-bit Minimal
- MySQL 5.7
配置 yum 源
# 下载
$ wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
# 安装 mysql 源
$ yum localinstall mysql57-community-release-el7-11.noarch.rpm
用下面的命令检查 mysql 源是否安装成功
$ yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community/x86_64 MySQL Connectors Community 153
mysql-tools-community/x86_64 MySQL Tools Community 110
mysql57-community/x86_64 MySQL 5.7 Community Server 424
安装 MySQL
使用 yum install
命令安装
$ yum install -y mysql-community-server
启动 MySQL 服务
启动/关闭服务的命令是 systemctl start|stop
$ systemctl start mysqld
用 systemctl status
查看 MySQL 状态
$ systemctl status mysqld
?.mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2020-06-18 10:38:20 CST; 38s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 13691 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 13629 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 13694 (mysqld)
CGroup: /system.slice/mysqld.service
?..13694 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
Jun 18 10:38:13 VM_0_10_centos systemd[1]: Starting MySQL Server...
Jun 18 10:38:20 VM_0_10_centos systemd[1]: Started MySQL Server.
设置开机启动
$ systemctl enable mysqld
# 重载所有修改过的配置文件
$ systemctl daemon-reload
修改 root 本地账户密码
mysql 安装完成之后,生成的默认密码在 /var/log/mysqld.log
文件中。使用 grep 命令找到日志中的密码。
$ grep 'temporary password' /var/log/mysqld.log
2020-06-18T02:38:15.404832Z 1 [Note] A temporary password is generated for root@localhost: kn;RYrESq9xz
首次通过初始密码登录后,使用以下命令修改密码:
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
flush privileges;
以后通过 update set 语句修改密码:
mysql> use mysql;
mysql> update user set password=PASSWORD('MyNewPass5!') where user='root';
mysql> flush privileges;
注意:mysql 5.7 默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示 ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 错误。
添加远程登录用户
默认只允许root帐户在本地登录,如果要在其它机器上连接 mysql,必须添加一个允许远程连接的帐户。或者修改 root 为允许远程连接(不推荐) 。
添加一个允许远程连接的帐户:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'zuozewei'@'%' IDENTIFIED BY 'Zuozewei2020!' WITH GRANT OPTION;
修改 root 为允许远程连接(不推荐):
mysql> use mysql;
mysql> UPDATE user SET Host='%' WHERE User='root';
mysql> flush privileges;
mysql> quit
设置默认编码为 utf8
mysql 安装后默认不支持中文,需要修改编码。
修改 /etc/my.cnf
配置文件,在相关节点(没有则自行添加)下添加编码配置,如下:
$ vim /etc/my.cnf
[mysqld]
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
重启 mysql 服务,查询编码:
$ systemctl restart mysqld
$ mysql -uroot -p
$ 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/ |
+--------------------------+----------------------------+
默认配置文件路径
- 配置文件:
/etc/my.cnf
- 日志文件:
/var/log/mysqld.log
- 服务启动脚本:
/usr/lib/systemd/system/mysqld.service
- socket 文件:
/var/run/mysqld/mysqld.pid
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)