CentOS7 Yum方式安装MySQ

1、添加MySQL Yum Repository(RPM包)。

a、下载地址在: http://dev.mysql.com/downloads/repo/yum/.

b、选择合适的版本

c、安装RPM

shell> sudo rpm -Uvh platform-and-version-specific-package-name.rpm

例如我下载的文件是 mysql57-community-release-el7-8.noarch.rpm 那么命令为

shell> sudo rpm -Uvh mysql57-community-release-el7-8.noarch.rpm


2、选择想要安装的版本。

shell> yum repolist all | grep mysql

默认情况下最新版本显示为enable,也就是MySQL5.7 ,如果直接安装的话就会安装MySQL5.7版本

这个文件显示的是5.6是因为我修改了配置文件。


3、如何修改配置文件,选择自己想要安装的版本。

编辑 /etc/yum.repos.d/mysql-community.repo

默认是这样的(需要将enabled设置为0) 为0的意思就是禁用。

[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版本的 (enabled设置为1)

# 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


4、安装MySQL

shell> sudo yum install mysql-community-server 


5、相关服务

shell> sudo service mysqld start    启动服务

shell> sudo service mysqld restart 重启

shell> sudo service mysqld stop 停止


6、启动后修改密码以及设置远程登录

mysqladmin -u root password newpass   修改密码

设置 ROOT 远程连接  update user set host = '%'   where user='root';


7、登陆问题:

  mysqladmin: connect to server at 'localhost' failed error: 'Access denied for user 'root'@'localhost' (using password: YES)'

  1:停止mysql服务: service mysqld stop

  2:执行命令:

 a:   mysqld_safe --skip-grant-tables & mysql -uroot -p        回车进入

 b:   use mysql;    切换到mysql数据库

         c:   update user set password=PASSWORD("newpass")where user="root"; 

更改密码为 newpass , 这里一定上PASSWORD("xxx") ,PASSWORD是一个函数

         d:    flush privileges; 更新权限

         e:    quit;   退出

  3:重启mysql服务:service mysqld restart

  4:链接数据库:mysql -uroot -p 新密码



8、CentOS7中关闭selinux

http://www.centoscn.com/CentOS/config/2015/0618/5681.html

编辑配置文件

vim /etc/selinux/config  

设置为禁用

#SELINUX=enforcing  
SELINUX=disabled

保存配置后重启

sestatus  


9、解决MySQL没有权限问题Can't create test file /var/lib/mysql/localhost.lower-test

chown -R mysql:mysql /data/mysql 







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值