Centos7 yum安装Mysql

首先 将mysql加到yum仓库中

[root@localhost ~]# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
[root@localhost ~]#  rpm -ivh mysql-community-release-el7-5.noarch.rpm
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-release-el7-5    ################################# [100%]
[root@localhost ~]# yum repolist all | grep mysql 
mysql-connectors-community/x86_64 MySQL Connectors Community        启用:    141
mysql-connectors-community-source MySQL Connectors Community - Sour 禁用
mysql-tools-community/x86_64      MySQL Tools Community             启用:    105
mysql-tools-community-source      MySQL Tools Community - Source    禁用
mysql55-community/x86_64          MySQL 5.5 Community Server        禁用
mysql55-community-source          MySQL 5.5 Community Server - Sour 禁用
mysql56-community/x86_64          MySQL 5.6 Community Server        启用:    513
mysql56-community-source          MySQL 5.6 Community Server - Sour 禁用
mysql57-community-dmr/x86_64      MySQL 5.7 Community Server Develo 禁用
mysql57-community-dmr-source      MySQL 5.7 Community Server Develo 禁用
[root@localhost ~]# yum repolist enabled | grep mysql
mysql-connectors-community/x86_64       MySQL Connectors Community           141
mysql-tools-community/x86_64            MySQL Tools Community                105
mysql56-community/x86_64                MySQL 5.6 Community Server           513

只需要把5.7的enabled 改成1  把5.6的enabled改成0 就行了

[root@localhost ~]# vi  /etc/yum.repos.d/mysql-community.repo  

[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

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

# 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/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# 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/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

安装

[root@localhost ~]#  yum install mysql-community-server
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 三 2020-01-15 09:31:26 CST; 16s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 16903 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 16853 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 16907 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─16907 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

1月 15 09:31:11 localhost.localdomain systemd[1]: Starting MySQL Server...
1月 15 09:31:26 localhost.localdomain systemd[1]: Started MySQL Server.
[root@localhost ~]# mysql --version
mysql  Ver 14.14 Distrib 5.7.29, for Linux (x86_64) using  EditLine wrapper

设置root的密码

[root@localhost ~]# vi /etc/my.cnf
[mysqld]
skip-grant-tables
[root@localhost ~]# systemctl restart mysqld
[root@localhost ~]# mysql
mysql> use mysql;
mysql> update mysql.user set authentication_string = password('123456') where user = 'root' and host = 'localhost';
Query OK, 1 row affected, 1 warning (0.06 sec)
Rows matched: 1  Changed: 1  Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.05 sec)

最后把/etc/my.cnf文件里的skip-grant-tables删除掉就行了

posted @ 2020-01-15 09:49  星火撩原  阅读(234)  评论(0编辑  收藏  举报