安装环境
- [x] CentOS 7
安装过程
配置yum源
Centos上默认是没有yum源的,yum安装的是MariaDB。所以我们需要自己先配置yum源。
下载yum源
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
安装yum源
rpm -Uvh mysql57-community-release-el7-11.noarch.rpm
在yum中查看有哪些Mysql版本
yum repolist all | grep mysql
※查询结果
[root@localhost ~]# yum repolist all | grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
mysql-connectors-community/x86_64 MySQL Connectors Community enabled: 118
mysql-connectors-community-source MySQL Connectors Community - disabled
mysql-tools-community/x86_64 MySQL Tools Community enabled: 95
mysql-tools-community-source MySQL Tools Community - Sourc disabled
mysql-tools-preview/x86_64 MySQL Tools Preview disabled
mysql-tools-preview-source MySQL Tools Preview - Source disabled
mysql55-community/x86_64 MySQL 5.5 Community Server disabled
mysql55-community-source MySQL 5.5 Community Server - disabled
mysql56-community/x86_64 MySQL 5.6 Community Server disabled
mysql56-community-source MySQL 5.6 Community Server - disabled
mysql57-community/x86_64 MySQL 5.7 Community Server enabled: 364
mysql57-community-source MySQL 5.7 Community Server - disabled
mysql80-community/x86_64 MySQL 8.0 Community Server disabled
mysql80-community-source MySQL 8.0 Community Server - disabled
安装
yum install -y mysql-community-server
启动
开机启动:systemctl enable mysqld
启动:systemctl start mysqld
查看MySql状态:systemctl status mysqld
查看生成的随机密码
MySQL5.7在初始化的时候会随机生成一个密码,我们可以通过查看Log文件直接拿到密码。
查看随机生成的密码
grep 'temporary password' /var/log/mysqld.log
※执行命令
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
2019-09-29T09:37:36.366271Z 1 [Note] A temporary password is generated for root@localhost: XXXXXXXXXXXX
登录MySQL
mysql -uroot -p
※执行命令
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.27
Copyright (c) 2000, 2019, 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>
修改密码
注意这个地方,MySQL在5.7.6以前修改密码是第一个方法修改密码,在之后版本使用的是第二种方法
MySQL<5.7.6 | MySQL>=5.7.6 |
---|---|
SET PASSWORD = PASSWORD(''); | ALTER USER USER() IDENTIFIED BY ''; |
这里文章中使用的是MySQL版本是5.7.27,所以使用的是第二个。
※执行命令
mysql> ALTER USER USER() IDENTIFIED BY '************';
Query OK, 0 rows affected (0.00 sec)
参考文章
https://www.cnblogs.com/bigbrotherer/p/7241845.html
https://blog.csdn.net/muziljx/article/details/81541896
原创文章,作者:zerokong,如若转载,请注明出处:
https://www.zerokong.com/%E5%AD%A6%E4%B9%A0/CentOS7%E4%B8%8B%E9%80%9A%E8%BF%87yum%E6%96%B9%E5%BC%8F%E5%AE%89%E8%A3%85MySQL5-7.html