Linux yum安装MySQL5.7

来源:互联网 发布:php 设置脚本执行时间 编辑:程序博客网 时间:2024/06/07 00:56

 

 一、安装配置MySQL的yum源

1
2
3
4
5
6
7
8
9
10
# 安装MySQL的yum源,下面是RHEL6系列的下载地址
rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
# 安装yum-config-manager
yum install yum-utils -y
# 禁用MySQL5.6的源
yum-config-manager --disable mysql56-community
# 启用MySQL5.7的源
yum-config-manager --enable mysql57-community-dmr
# 用下面的命令查看是否配置正确
yum repolist enabled | grep mysql

    检查是否有mysql57-community-dmr这个源,如上图所示。

    二、yum安装MySQL5.7

1
2
# 安装MySQL5.7
yum install mysql-community-server

    三、启动MySQL

1
2
3
4
5
# 禁用selinux
setenforce 0
sed -i '/^SELINUX=/c\SELINUX=disabled' /etc/selinux/config 
# 启动mysqld,启动之前先修改/etc/my.cnf配置文件,本文用默认的配置。
service mysqld start

    四、连接MySQL并修改密码

输入mysql,无法登陆,按以下操作

#1.停止mysql数据库
service mysqld stop
 
#2.执行如下命令
mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
 
#3.使用root登录mysql数据库
mysql -u root mysql
 
#4.更新root密码
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
#最新版MySQL请采用如下SQL:
mysql> UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';
 
#5.刷新权限 
mysql> FLUSH PRIVILEGES;
 
#6.退出mysql
mysql> quit
 
#7.重启mysql
service mysqld stop
 
#8.使用root用户重新登录mysql
mysql -uroot -p 
Enter password: <输入新设的密码newpassword>

原创粉丝点击