- 下载mysql源包
exec:wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
- 安装mysql源
exec:yum localinstall mysql57-community-release-el7-8.noarch.rpm
notice:如果需要安装5.6版本,可以修改vim /etc/yum.repos.d/mysql-community.repo源,改变默认安装的mysql版本。比如要安装5.6版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1。 - 安装mysql
exec:yum install mysql-community-server
- 启动mysql
exec:systemctl start mysqld
(centos7可用systemctl启动服务) - 将mysql服务设置为开机启动
exec:systemctl enable mysqld
exec:systemctl daemon-reload
- 修改mysql登录密码
mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:
exec:grep 'temporary password' /var/log/mysqld.log
(此命令会得到临时密码)
exec:mysql -uroot -p
(后面跟上上一步得到的密码)
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '(新密码)'
;
notice:默认密码检查策略要求密码必须同时包含:大|小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误。 - 允许远程访问mysql数据库
mysql> GRANT ALL PRIVILEGES ON *.* TO 'yangxin'@'%' IDENTIFIED BY 'Yangxin0917!' WITH GRANT OPTION;
GRANT命令详解:http://blog.csdn.net/wxy1234556/article/details/78956929 - 修改mysql默认字符集
vim /etc/my.cnf
添加如图中所示内容
- 允许mysql端口通过防火墙
firewall-cmd --zone=public --add-port=3306/tcp --permanent
查看是否开放成功
firewall-cmd --list-ports
命令含义:
–zone #作用域
–add-port=3306/tcp #添加端口,格式为:端口/通讯协议
–permanent #永久生效,没有此参数重启后失效
centos7安装mysql5.7
最新推荐文章于 2023-12-21 11:13:05 发布