参考:https://www.jb51.net/article/168465.htm
在MySQL官网中下载YUM源rpm安装包:http://dev.mysql.com/downloads/repo/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
检查mysql源是否安装成功
yum repolist enabled | grep "mysql.*-community.*"
# 查看mysql源
rpm -qa |grep mysql
# 卸载mysql源
rpm -e --nodeps mysql-community-release-el6-5.noarch
可以修改yum源,改变默认安装的mysql版本。比如要安装5.7版本,将5.7源的enabled=0改成enabled=1即可。vim /etc/yum.repos.d/mysql-community.repo
安装MySQL
yum install mysql-community-server
启动MySQL服务
systemctl start mysqld
开机启动
systemctl enable mysqld
systemctl daemon-reload
配置跳过密码:
# 跳过密码验证(`/etc/my.cnf`)
skip-grant-tables
有密码的,mysql安装完成之后,在/var/log/mysqld.log
文件中给root生成了一个默认密码
grep 'temporary password' /var/log/mysqld.log
修改密码:
mysql> flush privileges;
mysql> set password for 'root'@'localhost'=password('123456');
添加远程登录用户
mysql> GRANT ALL PRIVILEGES ON *.* TO 'yangxin'@'%' IDENTIFIED BY 'Yangxin0917!' WITH GRANT OPTION;
# 或者
mysql> use mysql;
mysql> update user set host = '%' where user = 'root';
mysql> select host, user from user;
mysql> flush privileges;
配置默认编码为utf8(/etc/my.cnf
)
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
重新启动mysql服务。
防火墙开放
// --permanent 永久生效,没有此参数重启后失效
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --zone=public --add-port=1000-2000/tcp --permanent
网友评论