一、安装NGINX和PHP
# 先删除系统可能自带的PHP和nginx,用来面命令查找是否有安装
[root@localhost ~]# rpm -qa |grep php
[root@localhost ~]# rpm -qa |grep nginx
# 强制删除软件包,软件包全称就是上面通过rpm -qa 查询到的软件包全名
[root@localhost ~]# rpm -e --nodeps {软件包全称}
# 安装yum的epel源,这里推荐用阿里云的镜像安装,包更全。
[root@localhost ~]# rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
# 安装nginx
[root@localhost ~]# yum install -y nginx
# 安装php的源
[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# 安装php已经会用到扩展
[root@localhost ~]# yum install -y php70w-devel php70w-pear php70w-pecl php70w-gd php70w-opcache php70w-cli php70w-pdo php70w-process php70w-pecl-apcu php70w-mcrypt php70w-mysql php70w-fpm php70w-pecl-memcached php70w-common php70w-xml php70w-mbstring php70w-pecl-igbinary
# 检查是否安装成功
[root@localhost ~]# nginx -v
nginx version: nginx/1.16.1
[root@localhost ~]# php -v
PHP 7.0.33 (cli) (built: Dec 6 2018 22:30:44) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.33, Copyright (c) 1999-2017, by Zend Technologies
二、安装MYSQL
#删除mariadb
#centos7 默认会安装mysql的另一个分支版本mariadb,在安装mysql前,需要将其删除
# 查出mariadb的rpm包
[root@localhost ~]# rpm -qa|grep mariadb
[root@localhost ~]# mariadb-libs-5.5.44-2.el7.centos.x86_64
# 忽略依赖关系,删除此包
[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
2. 添加官方yum源并安装mysql
# 下载安装此yum仓库
[root@localhost ~]# rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
# 安装完成后,此yum源仓库默认是安装mysql最新版8.0版本。
# 需要我们修改一下文件中的下列项,使其下载5.7版本,如果要安装别的版本,就打开对应版本,将别的版本关闭即可。
[root@localhost ~]# vim /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=1 # 这里将0改为1,开启5.7版本
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 # 这里将1改为0,关闭8.0版本
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
----------------------------------------------------------------
# 修改完成后,安装mysql5.7
[root@localhost ~]# yum install -y mysql-community-server
安装完成后,配置文件为 /etc/my.cnf 根据实际情况进行配置。
3. 启动服务,开启远程访问
# 启动mysql服务
[root@localhost ~]# systemctl start mysqld
# 设为开启自启动
[root@localhost ~]# systemctl enable mysqld
# 第一次启动mysql后,会自动生成一个初始密码在日志文件中,默认的日志文件路径为:/var/log/mysqld.log
# 找出初始化密码
[root@localhost ~]# cat /var/log/mysqld.log |grep password
2019-06-18T12:12:04.161088Z 1 [Note] A temporary password is generated for root@localhost: 2%w)IDysCVZQ
# 这里密码就是上面输出的那段,使用此密码登录mysql
[root@localhost ~]# mysql -u root -p
# 复制密码输出,进入mysql
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.26
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>
# 修改密码,mysql5.7的默认密码强度很高,需要有大小写,符号和数字,长度大于6,缺一不可
mysql> alter user 'root'@'localhost' identified by 'your_password';
Query OK, 0 rows affected (0.00 sec)
# 如果你不像要这么复杂的密码,修改密码强度设定为最低,即只判断密码长度
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
# 开启远程访问
$ grant all privileges on *.* to 'root'@'%' identified by 'your_password';
Query OK, 0 rows affected, 1 warning (0.00 sec)
# 刷新权限生效
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
# 到此就完成了mysql的最初设置了,现在就可以用账号密码,访问此mysql服务了
# 访问之前别忘了要打开数据库3306端口
$ firewall-cmd --add-port=3306/tcp --permanent
$ firewall-cmd --reload
修改密码
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.24
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password.length=1;
Query OK, 0 rows affected (0.00 sec)
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
遇到的问题
mysql> set global validate_password_policy=0;
ERROR 1193 (HY000): Unknown system variable 'validate_password_policy'
mysql> set global validate_password_length=4
ERROR 1193 (HY000): Unknown system variable 'validate_password_length'
问题原因
// 适用于sql的老版本如mysql5.0
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=4
// 新版本如mysql8.0就不支持了
// 为啥呢,进入mysql命令后,输入下面命令就清清楚楚了!
mysql> SHOW VARIABLES LIKE 'validate_password%';
// 结果如下
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 8 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | MEDIUM |
| validate_password.special_char_count | 1 |
+--------------------------------------+--------+
7 rows in set (0.01 sec)
实际解决
在Mysql中输入如下命令
mysql> set global validate_password.policy=0; // 调整设置密码策略
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password.length=1; //调整设置密码长度
Query OK, 0 rows affected (0.00 sec)
mysql> alter user 'root'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.01 sec)
# 开启远程访问
$ grant all privileges on *.* to 'root'@'%' identified by 'your_password';
Query OK, 0 rows affected, 1 warning (0.00 sec)
# 刷新权限生效
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
网友评论