频道栏目
首页 > 系统 > 其他 > 正文

Centos7下安装Mysql5.7

2017-06-19 09:34:38      个评论    来源:  
收藏   我要投稿

Centos7下安装Mysql5.7

一、环境

centos 7.0 64位


Centos7 默认没有安装mysql,而是安装的mariadb。首先我们就要先卸载mariadb
[root@sunny software]# rpm -qa | grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@sunny software]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64

查看是否存在别的版本的mysql
[root@sunny software]# rpm -qa|grep -i mysql
[root@sunny software]# 

如果有,全部卸载,我这里是没有的


下载mysql5.7 源
[root@sunny software]# wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
[root@sunny software]# ls
jdk-7u75-linux-x64.rpm  mysql57-community-release-el7-7.noarch.rpm

安装源
[root@sunny software]# yum localinstall -y mysql57-community-release-el7-7.noarch.rpm

查看系统默认mysql版本
[root@sunny software]# vim /etc/yum.repos.d/mysql-community.repo

[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# 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/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
~                                                                                                                                                                                            
~                                                                                                                                                                                            
~                                   

需要安装哪个版本,就将那个版本的enabled设为1,还需要将gpgcheck设为0


安装mysql服务
[root@sunny software]# yum clean all
[root@sunny software]# yum makecache
[root@sunny software]# yum install -y mysql-community-server

启动mysql
[root@sunny software]# systemctl start mysqld.service
[root@sunny software]# systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2017-06-18 14:48:32 CST; 10min ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 3485 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 3468 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 3489 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─3489 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Jun 18 14:48:29 sunny systemd[1]: Starting MySQL Server...
Jun 18 14:48:32 sunny systemd[1]: Started MySQL Server.
[root@sunny software]# 

查看mysql版本
[root@sunny software]# mysql -V
mysql  Ver 14.14 Distrib 5.7.18, for Linux (x86_64) using  EditLine wrapper
[root@sunny software]# 

5.7安装成功


将mysql设置为开机启动
[root@sunny software]# systemctl enable mysqld.service
[root@sunny software]# systemctl daemon-reload
[root@sunny software]# 

三、修改密码

查看随机密码
5.7版本会有一个随机的密码,并且强制要求使用者修改密码
我们可以在/var/log/mysqld.log这个日志里面看到
[root@sunny software]# grep 'temporary password' /var/log/mysqld.log
2017-06-18T08:38:54.551106Z 1 [Note] A temporary password is generated for root@localhost: SIYesQrnw0!&
[root@sunny software]# 

登录mysql
[root@sunny software]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.18

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Taokai@1017';
Query OK, 0 rows affected (0.00 sec)

mysql> 

mysql5.7默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示ERROR 1819 (HY000): Your password does not satisfy the current policy requirements错误。


开启远程连接
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Taokai@1017' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> 

我这里开的root,当然这样不好。使用数据库工具,返现数据连接上了

上一篇:Centos中软件安装
下一篇:Nandflash存储结构和地址分配
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 |

版权所有: 88bifa.com--致力于做实用的IT技术学习网站