CentOS-7.5 安装 社区版 MySQL-5.7

1、实验环境

服务器类型:VMware虚拟机
服务器操作系统:CentOS-7.5
服务器名称:CentOS-1
服务器IP:192.168.218.128
防火墙+selinux均已关闭
网络连通状况:服务器可以上外网

2、MySQL-5.7 安装源的下载

1)先卸载系统自带的mariadb
[[email protected] ~]#
[[email protected] ~]# rpm -qa mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[[email protected] ~]#
[[email protected] ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
[[email protected] ~]#
[[email protected] ~]# rpm -qa mariadb

[[email protected] ~]#

2)下载并安装mysql-5.7的安装源
yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm #安装mysql-5.7的安装源

[[email protected] ~]# ll /etc/yum.repos.d/ | grep ‘mysql-community*‘

[[email protected] ~]#
[[email protected] ~]# yum list mysql-community-server

3、删除Linux系统原来自带的 my.cnf 文件(如果存在的话)

[[email protected] ~]# rm -rf /etc/my.cnf
[[email protected] ~]#

4、安装 MySQL-5.7
[[email protected] ~]#
[[email protected] ~]# yum -y install mysql-community-server #安装mysql
[[email protected] ~]# rpm -q mysql-community-server
mysql-community-server-5.7.29-1.el7.x86_64
[[email protected] ~]#

5、启动MySQL-5.7
[[email protected] ~]#
[[email protected] ~]# systemctl start mysqld.service #启动mysql
[[email protected] ~]# systemctl enable mysqld.service #设置mysql服务为自启动
[[email protected] ~]#
[[email protected] ~]# lsof -i:3306

[[email protected] ~]#

6、修改配置文件
[[email protected] ~]#
[[email protected] ~]# mkdir /var/lib/mysql/binary_log #创建用于存放binlog日志的目录‘binary_log‘
[[email protected] ~]# ls /var/lib/mysql/binary_log
[[email protected] ~]#
[[email protected] ~]# ll /var/lib/mysql | grep ‘binary_log‘ #查看‘binary_log‘目录的权限

[[email protected] ~]#
[[email protected] ~]# chown -R mysql.mysql /var/lib/mysql/binary_log #修改该目录权限
[[email protected] ~]# ll /var/lib/mysql | grep ‘binary_log‘

[[email protected] ~]# vim /etc/my.cnf #编辑修改mysql服务器的配置文件
说明:因为后期要配置主从同步,所以配置文件中设置server-id,以及binlog存储文件以master_a-binlog开头(master_a表示第一个主服务器)

[[email protected] ~]# cat /etc/my.cnf #查看修改后的配置文件

[[email protected] ~]#
[[email protected] ~]# systemctl restart mysqld.service #重启mysql服务,使配置生效
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# ll /var/lib/mysql/binary_log/ #查看此时是否生成了binlog文件

7、MySQL登录测试
[[email protected] ~]#
[[email protected] ~]# grep ‘temporary‘ /var/log/mysqld.log #查看系统分配的mysql临时登录密码

[[email protected] ~]# mysql -uroot -p‘piDr2,8x#W6S‘ #使用临时密码登录mysql并做查询操作,发现查询失败

[[email protected] ~]#
[[email protected] ~]# mysql -uroot -p‘piDr2,8x#W6S‘ #再次登录mysql,根据错误提示进行排错
mysql>
mysql> show databases; #查看错误提示
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql>
mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘[email protected]‘; #根据错误提示进行排错
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> flush privileges; #刷新权限
Query OK, 0 rows affected (0.00 sec)

mysql>

8、使用安全配置向导设置MySQL(MySQL初始化)
[[email protected] ~]#
[[email protected] ~]# mysql_secure_installation #安全配置向导
Securing the MySQL server deployment.

Enter password for user root: #输入root用户密码‘[email protected]‘
The ‘validate_password‘ plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 100 #预计密码强度为100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y #更改root用户密码(是或者否)

New password: #输入新root密码,此处新密码设置为“Mysql.2020”

Re-enter new password: #再次输入新root密码“Mysql.2020”

Estimated strength of the password: 100 #预计密码强度为100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y #您是否要继续使用提供的root密码(是或者否)
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y #是否删除匿名用户
Success.

Normally, root should only be allowed to connect from
‘localhost‘. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y #禁止root用户从远程登录mysql服务器
Success.

By default, MySQL comes with a database named ‘test‘ that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y #是否删除测试数据库

  • Dropping test database...
    Success.
  • Removing privileges on test database...
    Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y #现在重新加载授权表
Success.

All done!
[[email protected] ~]#

9、MySQL登录
[[email protected] ~]#
[[email protected] ~]# mysql -uroot -p‘Mysql.2020‘

原文地址:https://blog.51cto.com/14783377/2485030

时间: 2024-11-10 00:16:50

CentOS-7.5 安装 社区版 MySQL-5.7的相关文章

windows 安装绿色版mysql

(1)到官网下载绿色版mysql:http://dev.mysql.com/downloads/mysql/ (2)下载好后,放在F:\mysql,解压出来 (3)进入到mysql-5.6.19-winx64这个文件夹,用记事本打开my-default.ini 把里面的内容替换: # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.6/en/server-configurati

centos通过yum安装mariadb(mysql)无法启动服务或者找不到mysql.sock

今天在某云主机(centos7)安装(yum install方式)mariadb(即开源mysql)后,无法启动mariadb,其实是安装不完整,当然启动不了,更不用说输入"mysql -u root"提示Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)了 .没什么技术含量的解决方法开始了. 安装mariadb,先搜索一发: $ sudo yum search mariadb 出现: $ s

CentOS 7 AMD64安装nginx和mysql

NGINX: rpm -ivh http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.8.0-1.el7.ngx.x86_64.rpm 查看: yum info nginx 安装: yum install nginx service nginx start MySQL: CentOS 7的yum源中貌似没有正常安装mysql时的mysql-sever文件,需要去官网上下载 # wget http://dev.mysql.com/get/my

转载:centos上yum安装apache+php+mysql等

1. 更新系统内核到最新. [[email protected] ~]#yum -y update 系统更新后,如果yum安装时提示错误信息,请执行以下命令修复. [[email protected] ~]#rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY* 2. 安装Apahce, PHP, Mysql, 以及php连接mysql库组件 y[[email protected] ~]#um -y install httpd php mysql mysql-serv

CentOS 下yum安装指定版本mysql的过程

在linux安装指定版本mysql是一个困难的事情,yum安装一般是安装的mysql5.1,现在经过自己不懈努力终于能用yum安装mysql5.5了. 1.安装mysql-5.5的yum源 rpm -ivh http://repo.mysql.com/yum/mysql-5.5-community/el/6/x86_64/mysql-community-release-el6-5.noarch.rpm 2.修改安装好的yum源 编辑 /etc/yum.repos.d/mysql-communit

centos系统yum安装apache+php+mysql

原文参考扩展来自:http://blog.csdn.net/lumengabc/article/details/38963609 先来解释一下,什么是 LAMP.正如标题所言,LAMP 实际上就是 Linux.Apache.MySQL.PHP 四个名称的缩写,当然最后一个 "P" 还有其他说法是 Perl 或者 Python.不用多说了,本文讲解的就是 Linux.Apache.MySQL.PHP 这四个东西,所以就这样解释了. 自己很早就在做网站,最初玩的是 ASP,后来主要研究 .

CentOS系统下安装以及卸载mysql

CentOS7的yum源中默认好像是没有mysql的.为了解决这个问题,我们要先下载mysql的repo源. 1. 下载mysql的repo源 [[email protected] `]$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm 2. 安装mysql-community-release-el7-5.noarch.rpm包 [[email protected] `]$sudo rpm -ivh mysq

在aliyun主机上通过yum方式安装Percona版MYSQL 5.7

Aliyun主机环境:CPU:1C  MEM:2G   OS:centos 6.8 1.安装percona软件包源 yum install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm 2.验证percona软件包源 yum  list | grep Percona-Server-server-57 3.安装mysql 5.7 yum install P

CENTOS 7.0 安装discuz ,搭 mysql +php+apache 环境

CentOS 7的yum源中没有Mysql-sever文件,需要去官网上下载: 1.下载支持Mysql-sever的rpm文件 # wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm 2.安装rpm包 # rpm -ivh mysql-community-release-el7-5.noarch.rpm 3.安装mysql-sever # yum install mysql-community-server

centos 6.5安装并配置mysql

折腾了半天终于把mysql安装并配置好了,以下是安装步骤和遇到问题的解决方式 1.查看机器上是否已经安装了mysql或其相关项 # yum list installed | grep mysql如果安装的话命令执行完显示的结果类似于:mysql-community-common.x86_64 5.7.21-1.el6 @mysql57-community-dmr 些时需要删除已经存在的mysql及其相关项,执行以下命令# yum -y remove mysql-community-common.