centos7安装mysql mmm_CentOS下yum方式安装MySQL

0、检查是否安装老版本的MySQL和mariadb,如果有先卸载,确保不存在 /etc/my.cnf 文件

shell> rpm -qa | grep mysql

shell> rpm -qa | grep mariadb

mariadb-libs-5.5.52-1.el7.x86_64

shell> yum remove mariadb-libs

... ...

Removed:

mariadb-libs.x86_64 1:5.5.52-1.el7

Dependency Removed:

postfix.x86_64 2:2.10.1-6.el7 redhat-lsb-core.x86_64 0:4.1-27.el7.centos.1

Complete!

shell> rpm -qa | grep mariadb

shell> ll /etc/my*

ls: cannot access /etc/my*: No such file or directory

1、先到mysql官网查看yum repository,根据CentOS版本,注意文件名,如下图红框所示

7c9fbc9533382b07bd0e6fc6e6e1eba6.png

2、增加 MySQL Yum Repository

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

例如:要在CentOS 6.5下安装MySQL输入如下命令

shell>sudo yum localinstall https://repo.mysql.com/mysql80-community-release-el6-1.noarch.rpm

要在CentOS 7.x下安装MySQL输入如下命令

shell>sudo yum localinstall https://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm

安装完成后,在 /etc/yum.repos.d/下有个 mysql-community.repo文件,MySQL的不同版本的安装配置都有,选择你想安装的版本,把enabled设为1。如下图:

8e22056010f02210fcf12026397eedc8.png

3、Selecting a Release Series

shell> yum repolist all | grep mysql

查看是否设为 enabled

ac6ead50278f0667eb7de36592dd9692.png

4、Installing MySQL

shell> sudo yum install mysql-community-server

如有需要,修改MySQL数据存储目录

shell> vim /etc/my.cnf

修改

datadir=/var/lib/mysql/data

5、Starting the MySQL Server

shell> sudo service mysqld start

Initializing MySQL database: [ OK ]

Starting mysqld: [ OK ]

6、设置开机启动

CentOS 6

shell> chkconfig mysqld on

CentOS 7

shell> systemctl enable mysqld.service

7、查看随机生成的密码

shell> grep 'temporary password' /var/log/mysqld.log

2018-06-28T22:01:13.609839Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: -TIMLMsTf7ay

8、登录MySQL

shell> mysql -uroot -p

Enter password: -TIMLMsTf7ay

ommands end with ; or \g.

Your MySQL connection id is 9

Server version: 8.0.11

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

9、修改root密码

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root@1234';

Query OK, 0 rows affected (0.43 sec)

10、允许root用户在任何地方进行远程登录,并具有所有库任何操作权限

MySQL 5.7

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Root@1234' WITH GRANT OPTION;

Query OK, 0 rows affected, 1 warning (0.13 sec)

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

MySQL 8.0 (注意密码策略更严格,要求大小写字母+数字+其他字符组合)

mysql> CREATE USER `root`@`%` IDENTIFIED WITH mysql_native_password BY 'Root@1234';

Query OK, 0 rows affected (0.42 sec)

mysql> GRANT ALL ON *.* TO `root`@`%` WITH GRANT OPTION;

Query OK, 0 rows affected (0.19 sec)

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值