安装部署数据库
本文使用MySQL5.7
下载安装数据库repo文件
wget https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm
rpm -ivh mysql80-community-release-el7-2.noarch.rpm
修改repo文件 将默认的8.0版本改成5.7
vi /etc/yum.repos.d/mysql-community.repo
# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
改为下面的,也就是说启用mysql5.7的版本
# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
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
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
查看修改好的版本
yum list |grep mysql
mysql-community-client.x86_64 5.7.26-1.el7 mysql57-community
安装MySQL
yum -y install mysql-community-server.x86_64
启动数据库并设置开机自启动
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# systemctl enable mysqld
查看mysql密码
[root@localhost ~]# cat /var/log/mysqld.log |grep “pass”
2019-07-09T08:39:30.367236Z 1 [Note] A temporary password is generated for root@localhost: pjjAa4zYy9!_
记住初始密码 登录并修改密码
[root@localhost ~]# mysql -u root -p’pjjAa4zYy9!_’
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.26
Copyright © 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> ALTER USER USER() IDENTIFIED BY ‘123456’;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)