centos su mysql_centos 7 安装 MYSQL 5.7

下载MySQL官方Yum Repository

在一个合适的地方把这个下下来

wget -i http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm

安装MySQL的Yum Repository

yum -y install mysql57-community-release-el7-7.noarch.rpm

安装MySQL数据库的服务器版本

yum -y install mysql-community-server

启动数据库

systemctl start mysqld.service

可以用命令systemctl status mysqld.service查看MySQL数据库启动后的服务状态。

获取初始密码

grep "password" /var/log/mysqld.log

会显示这么一句:

A temporary password is generated for root@localhost: su%lsu7Rx

这个乱七八糟的就是你的初始密码了,虽然有了密码,但是还是要修改密码后才能真正用起来,不然就会报错:

14d9f6ede179

不修改密码就会报错

修改root用户密码

mysql -uroot -p

Enter password: ####输入刚刚那一堆乱七八糟的东西

##……

##……

修改密码:

方法一:

mysql> set password for 'root'@'localhost'=password('123');

方法二:

alter user 'root'@'localhost' identified by '123';

我这里很懒,写的123,但是如果你也这么写,那就可能会报错:

14d9f6ede179

你的密码太简单了!

仔细看一下初始密码,发现它有:大写、小写、数字、特殊符号,长度在8位以上。那么你也需要弄一个符合这些条件的密码来。当然你也可以修改mysql的配置使得密码的要求被降低,但是我觉得有规律的话,复杂一点也没啥问题嘛。附上使用简单密码教程。

安装结束

修改完密码后 使用exit退出mysql,然后再执行mysql -uroot -p时,用上的就是刚刚改好的密码了。

[root@hlxfdymbz2 ~]# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 13

Server version: 5.7.22 MySQL Community Server (GPL)

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> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

mysql> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| sys |

+--------------------+

4 rows in set (0.00 sec)

mysql> exit

Bye

这样,mysql就全部弄好能用了。

其他

当我用Navicat 连刚刚弄好的数据库时,发现一直连不上,原因和nginx里注意部分出现的问题一样,是安全组配置问题。因为我新买的服务器的安全组入网配置没有3306端口,而数据库的端口大多默认为3306(你也可以改咯?),所以连不上,去安全组配置以下,协议类型为MySQL:

14d9f6ede179

安全组规则协议类型

配置好后终于连上了,但是却又报了个错。

1130,ERROR 1130: Host xxx.xxx.xxx.xxx is not allowed to connect to this MySQL server

原因无法给远程连接的用户权限。这时候我们修改下权限就好啦:

Sql代码 :

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

之后再执行:

flush privileges;

刷新下权限就OK了。

再通过Navicat 去连接,就可以连上数据库了。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值