#CentOS7 yum安装MySQL5.7
安装MySQL yum知识库
查看:MySQL Yum,找到yum 知识库说明,然后根据需要下载安装。
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
yum localinstall -y mysql80-community-release-el7-3.noarch.rpm
修改yum配置,默认安装mysql57
vi /etc/yum.repos.d/mysql-community.repo
将[mysql57-community]下的enabled修改为1
[mysql80-community]的enabled修改为0。
安装mysql
[root@localhost ~]# yum install mysql-community-server -y
启动mysql
[root@localhost ~]# systemctl start mysqld
登录root并修改密码
[root@localhost ~]# grep "password" /var/log/mysqld.log #查看默认密码
[root@localhost ~]# mysql -uroot -p
mysql> set password for 'root'@'localhost'="new_password";
mysql> exit
修改默认字符集
vi /etc/my.cnf
#char set settings
#全局字符集
character_set_server=utf8
#字符集编码
collation_server=utf8_general_ci
如果设置utf8mb4使用如下
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
防火配置
firewalld
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-port=3306/tcp
[root@localhost ~]# service firewalld restart
iptables
vi /etc/sysconfig/iptables,添加:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 3306 -j ACCEPT
或
# iptables -A INPUT -m state --state NEW -m udp -p udp --dport 5432 -j ACCEPT
# iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT