一、添加配置文件
1、进入/etc/yum.repos.d/目录下
执行
cd /etc/yum.repos.d/
2、添加以下文件mysql-community.repo文件,内容如下:
vi mysql-community.repo
以上对应的是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/5/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
--------------------------------------------------------------------------------------------------------
以下对应的是5.7版本
# Note: MySQL 5.7 is currently in development. For use at your own risk.
# Please read with sub pages: https://dev.mysql.com/doc/relnotes/mysql/5.7/en/
[mysql57-community-dmr]
name=MySQL 5.7 Community Server Development Milestone Release
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
3、执行
yum install mysql-community-server
我用的是5.6版本的内容,在安装的过程中,报以下错误:
GPG key retrieval failed: [Errno 14] curl#37 - "Couldn't open file /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql"
很显然,本地没有RPM-GPG-KEY-mysql文件,于是对上文的mysql-community.repo做了一下修改,修改后的内容如下:
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/5/$basearch/
enabled=1
gpgcheck=0
重新执行
扫描二维码关注公众号,回复:
9966840 查看本文章
yum install mysql-community-server
安装OK
4、安装完毕后,需要配置密码
a、修改/etc/my.cnf文件,在mysqld配置项下面增加skip-grant-tables,如下图
b、重启mysql服务
service mysqld restart
c、无密码登陆mysql
update user set password = password('新的密码'),password_expired='N' where user = 'root';
flushprivileges;
d、重启mysql服务
service mysqld restart
e、使用新密码访问mysql
mysql -u root -p
输入新密码,回车即完成访问mysql;
f、修改/etc/my.cnf文件,删除skip-grant-tables
6、开启远程权限,不然本地机器,无法访问到服务器
a、进入数据库
b、使用mysql,执行:
use mysql;
c、然后执行修改权限的命令:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
d、执行完毕,清除一下缓存,刷新权限
flush privileges;
e、查看权限是否开启
select host,user from user;
f、现在mysql里的数据库已经安装完毕,也开启了远程连接。
参考文章:
数据库安装:https://www.cnblogs.com/ivictor/p/4807353.html
免密登录:https://blog.csdn.net/qq_37202864/article/details/82839814