一步一步教你centos7.3安装mysql5.7

1,到http://dev.mysql.com/downloads/repo/yum/下载yum源
wget https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
2,安装yum源,替换系统默认的mysql源
yum localinstall mysql57-community-release-el7-11.noarch.rpm
3,验证mysql源是否添加成功
yum repolist enabled | grep "mysql.*-community.*"
4,查看所有mysql的发行版本列表
yum repolist all | grep mysql
5,禁用5.7,安装5.6执行如下命令
yum-config-manager --disable mysql57-community
yum-config-manager --enable mysql56-community
6,步骤5也可以编辑/etc/yum.repos.d/mysql-community.repo文件,达到启用禁用
    默认5.7的文件
        [mysql57-community]
        name=MySQL 5.7 Community Server
        baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
        enabled=1
        gpgcheck=1
        gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
    修改成5.6的
        # Enable to use MySQL 5.6
        [mysql56-community]
        name=MySQL 5.6 Community Server
        baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/
        enabled=1
        gpgcheck=1
        gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

最后执行repolist enabled | grep mysql是修改生效
7,安装mysql
yum install mysql-community-server
注意:同时也安装了mysql-community-client,mysql-community-common,mysql-community-libs这三个组件
8,启动mysql服务
service mysqld start
9,检查mysql服务状态
service mysqld status
10,mysql初始化时会生成一个临时密码(Pr,KL=?ab7y/),密码为
grep 'temporary password' /var/log/mysqld.log
11,修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'RestyleTest@2017';
注意:密码要包含一个大写字符,一个小写字符,数字,特殊字符,不少于8位.
12,授权root用户可以远程登录访问
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '新的密码' WITH GRANT OPTION;
FLUSH PRIVILEGES;
13,查看默认编码
show variables like '%character%';
14,配置默认编码为utf8
vi /etc/my.cnf
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
15,重启mysql服务
systemctl restart mysqld
16,关闭防火墙或禁用防火墙对3306端口的拦截
vi /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
service iptables restart

你可能感兴趣的:(Database)