yum安装MySQL数据库
yum安装方式
优点:操作简单易用。不用单独下载,服务器可以联网且yum源没有问题即可(可以选择国内的163/阿里源)
安装步骤:
1.关闭防火墙和selinux:
systemctl stop firewalld ##关闭防火墙
systemctl disable firewalld ##禁止防火墙开机自启
setenforce 0 ##关闭selinux
getenforce ##查看selinux状态
2.下载MySQL数据库的yum仓库
mysql的官方网站: www.mysql.com
[root@mysql-server ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
或者下载到本地上传到服务器
3,安装MySQL的yum仓库
[root@mysql-server ~]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm
[root@mysql-server ~]# yum -y install yum-utils #安装yum工具包
4,配置yum厂库
vi /etc/yum.repos.d/mysql-community.repo
1表示开启,0表示关闭
或者
yum-config-manager --enable mysql57-community 将禁用的yum源库启用
yum-config-manager --disable mysql80-community 将启用的yum源库禁用
5,安装MySQL数据库
[root@mysql-server ~]# yum install -y mysql-community-server
启动服务
[root@mysql-server ~]# systemctl start mysqld
设置开机启动
[root@mysql-server ~]# systemctl enable mysqld
6,查看系统设置的数据库密码并修改
密码保存在日志文件中
是root@localhost:后面的字符串
[root@mysql-server ~]# grep password /var/log/mysqld.log
2019-08-18T14:03:51.991454Z 1 [Note] A temporary password is generated for root@localhost: woHtkMgau9,w
修改密码:
两种方式:
第一种:
[root@mysql-server ~]# mysql -uroot -p'woHtkMgau9,w'
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 2
Server version: 5.7.27
....
mysql> alter user 'root'@'localhost' identified by 'QianFeng@123';
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
[root@mysql-server ~]# mysql -uroot -p'QianFeng@123'
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.27 MySQL Community Server (GPL)
...
mysql> exit
Bye
第二种:
mysqladmin -u root -p'旧密码' password '新密码'
注:修改密码必须大小写数字和特殊符号都有。
7,修改弱密码
[root@mysql-server ~]# vim /etc/my.cnf #在最后添加如下内容
validate_password=off
[root@mysql-server ~]# systemctl restart mysqld #重启mysql生效
可以用第二种方式修改为简单的密码:
[root@mysql-server ~]# mysqladmin -uroot -p'QianFeng@123' password 'qf123'