首页 > 系统 > CentOS > 正文

centos使用yum安装mysql

2024-06-28 14:33:17
字体:
来源:转载
供稿:网友

参考:http://dev.MySQL.com/doc/mysql-yum-repo-quick-guide/en/

1.增加yum数据源

(1.1)从http://dev.mysql.com/downloads/repo/yum/ 获取合适的数据源

(1.2)安装数据源包

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

eg:安装 Red Hat EnterPRise linux 7 / Oracle Linux 7 (Architecture Independent), RPM Package

shell> wget http://repo.mysql.com/mysql57-community-release-el7-7.noarch.rpmshell> sudo rpm-Uvh mysql57-community-release-el7-7.noarch.rpm

2.选择合适的安装版本

(2.1)查看mysql数据源中存在的包 

shell> sudo yum repolist all | grep mysql

(2.2)编辑 /etc/yum.repos.d/mysql-community.repo,启用相应的mysql版本

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

  ps: "enabled=1" 启用,"enabled=0" 禁用,上述配置则是安装"mysql 5.7",禁用"mysql 5.6"

(2.3)查看mysql启用列表

shell > sudo yum repolist enabled | grep mysqlmysql-connectors-community/x86_64      MySQL Connectors Community            17mysql-tools-community/x86_64           MySQL Tools Community                 27mysql57-community/x86_64               MySQL 5.7 Community Server            20

 3.安装mysql

shell> sudo yum install mysql-community-server  

 注意:在使用yum 安装 mysql 5.7过程中,会随机生成一个临时的root密码保存到错误日志("/var/log/mysqld.log"),可以使用如下命令进行查看:

shell > sudo grep 'temporary passWord' /var/log/mysqld.log

 因此安装mysql 5.7后,需要尽快修改密码。

4.启动mysql服务器

shell> yum --disablerepo=/* --enablerepo='mysql*-community*' list available

(4.1)启动命令

shell> sudo service mysqld start

(4.2)查看mysql状态

shell> sudo service mysqld status

5.mysql_secure_installation

使用mysql_secure_installation设置root密码,删除匿名用户等重要操作

shell> mysql_secure_installation

ps: 更多操作参考

http://dev.mysql.com/doc/refman/5.7/en/mysql-secure-installation.html

http://dev.mysql.com/doc/refman/5.7/en/default-privileges.html

6.安装mysql额外工具

(6.1)查看可用包名

shell> mysql_secure_installation

(6.2)安装包

shell> sudo yum install 包名

如:安装 mysql-workbench-community

shell> sudo yum install mysql-workbench-community

7.升级mysql

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

(7.2)执行update

shell> sudo yum update mysql-server

 或者使用下述命令更新所有包

shell> sudo yum update

8. centos7默认使用mariadb数据库代替mysql,先将mariadb相关包卸载

(8.1)查询 maridb 包命令

shell> sudo rpm -qa | grep -i mariadb

(8.2)删除 

shell> sudo rpm -e 相关包名

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表