本文档包括使用 PHP-FPM 为 Nginx 1.4.x HTTP 服务器安装和配置 PHP 的说明和提示。

本指南假定您已经从源代码成功构建 Nginx,并且其二进制文件和配置文件都位于 /usr/local/nginx。 如果您使用其他方式获取的 Nginx,请参考 » Nginx Wiki 并对照本文档完成安装。

本文档仅包含 Nginx 服务器的基本配置,它将通过 80 端口提供 PHP 应用的处理能力。 如果您需要超出本文档范围的安装配置指导,建议您查阅 Nginx 和 PHP-FPM 的文档。

需要注意的是,本文档一律使用 'x' 来表示版本号,请根据实际情况将 'x' 替换为对应的版本号。

  1. 建议您访问 Nginx Wiki » 安装 页面以获取并在您的系统上安装 Nginx。

  2. 获取并解压 PHP 源代码:

    tar zxf php-x.x.x
    
  3. 配置并构建 PHP。在此步骤您可以使用很多选项自定义 PHP,例如启用某些扩展等。 运行 ./configure --help 命令来获得完整的可用选项清单。 在本示例中,我们仅进行包含 PHP-FPM 和 MySQL 支持的简单配置。

    cd ../php-x.x.x
    ./configure --enable-fpm --with-mysql
    make
    sudo make install
    
  4. 创建配置文件,并将其复制到正确的位置。

    cp php.ini-development /usr/local/php/php.ini
    cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf
    cp sapi/fpm/php-fpm /usr/local/bin
    
  5. 需要着重提醒的是,如果文件不存在,则阻止 Nginx 将请求发送到后端的 PHP-FPM 模块, 以避免遭受恶意脚本注入的攻击。

    将 php.ini 文件中的配置项 cgi.fix_pathinfo 设置为 0 。

    打开 php.ini:

    vim /usr/local/php/php.ini
    

    定位到 cgi.fix_pathinfo= 并将其修改为如下所示:

    cgi.fix_pathinfo=0
    
  6. 在启动服务之前,需要修改 php-fpm.conf 配置文件,确保 php-fpm 模块使用 www-data 用户和 www-data 用户组的身份运行。

    vim /usr/local/etc/php-fpm.d/www.conf
    

    找到以下内容并修改:

    ; Unix user/group of processes
    ; Note: The user is mandatory. If the group is not set, the default user's group
    ;       will be used.
    user = www-data
    group = www-data
    

    然后启动 php-fpm 服务:

    /usr/local/bin/php-fpm
    

    本文档未涵盖对 php-fpm 进行进一步配置的信息,如果您需要更多信息,请查阅相关文档。

  7. 配置 Nginx 使其支持 PHP 应用:

    vim /usr/local/nginx/conf/nginx.conf
    

    修改默认的 location 块,使其支持 .php 文件:

    location / {root   html;index  index.php index.html index.htm;
    }

    下一步配置来保证对于 .php 文件的请求将被传送到后端的 PHP-FPM 模块, 取消默认的 PHP 配置块的注释,并修改为下面的内容:

    location ~* \.php$ {fastcgi_index   index.php;fastcgi_pass    127.0.0.1:9000;include         fastcgi_params;fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
    }

    重启 Nginx。

    sudo /usr/local/nginx/sbin/nginx -s stop
    sudo /usr/local/nginx/sbin/nginx
    
  8. 创建测试文件。

    rm /usr/local/nginx/html/index.html
    echo "<?php phpinfo(); ?>" >> /usr/local/nginx/html/index.php
    

    打开浏览器,访问 http://localhost,将会显示 phpinfo() 。

通过以上步骤的配置,Nginx 服务器现在可以以 SAPI SAPI 模块的方式支持 PHP 应用了。 当然,对于 Nginx 和 PHP 的配置,还有很多可用的选项, 请在对应的源代码目录执行 ./configure --help 来查阅更多配置选项。

获取并安装 PEAR 包管理器

获取并安装 PEAR 包管理器

视窗

下载并安装 PHP 后,您必须手动执行位于例如 c:\php\go-pear.bat. 或者, 使用浏览器下载 https://pear.php.net/go-pear.phar并将输出保存到名为go-pear.phar. 然后你可以运行

<span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#eeeeee">      <strong><code>
php go-pear.phar</code></strong></span></span></span>

在 Windows 命令提示符下开始安装。

安装程序会询问您一些问题,然后 PEAR 包管理器将安装在您在安装过程中指定的路径中。

最后,您必须将该安装路径添加到您的 PATH环境中。手动执行此操作(开始 > 控制面板 > 系统 > 环境)或运行(双击)PEAR_ENV.reg现在在 PHP 源目录中找到的新生成的文件。

之后,您可以通过pear在 Windows 命令提示符中运行命令来访问 PEAR 包管理器。

之后 改变php.ini,你将需要重新启动您的Web服务器。

现在检查 PEAR 是否有效。

Unix/Linux/BSD

使用 PHP 时,除非使用./configure 选项 ,否则已经安装了 PEAR 包管理器--without-pear

如果使用由 Unix/Linux/BSD 发行商提供的 PHP 版本,则可能需要手动安装 PEAR。在这种情况下,用户应查阅相应发行版的文档。

如果要重新安装包管理器,可以使用以下临时方式:

<span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#eeeeee">      <strong><code>
$ wget http://pear.php.net/go-pear.phar
$ php go-pear.phar</code></strong></span></span></span>

请注意,您可能需要通过 Unix/Linux/BSD 软件包管理器安装 wget 软件包。在 Debian 和 Ubuntu 上,这是通过以下方式完成的:

<span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#eeeeee">      <strong><code>$ sudo apt-get install wget</code></strong></span></span></span>

或者,通过浏览器下载 go-pear.phar 文件。

如果进程在没有任何输出的情况下退出,您的系统日志可能会包含以下几行:

<span style="color:#000000"><span style="background-color:#ffffff">suhosin[4705]:警报 - 包括文件名('phar://go-pear.phar/index.php')是不允许的 URL(攻击者“未设置 REMOTE_ADDR”,文件“/root/go-pear.phar”,第 1236 行)</span></span>

要解决此问题,请在/etc/php5/conf.d/suhosin.ini以下位置启用 phar :

<span style="color:#000000"><span style="background-color:#ffffff">suhosin.executor.include.whitelist = phar</span></span>

现在检查 PEAR 是否有效。

Mac OS X

使用如下所示的 curl 下载 go-pear.phar 文件或通过浏览器下载 go-pear.phar 文件。

<span style="color:#000000"><span style="background-color:#ffffff"><span style="background-color:#eeeeee">      <strong><code>
$ curl -O https://pear.php.net/go-pear.phar
$ php -d detect_unicode=0 go-pear.phar</code></strong></span></span></span>

您现在已准备好配置 PEAR 以进行安装。

首先,您需要更改安装基础。

  1. 所以输入 1,然后按 Enter。

  2. 输入 /usr/local/pear

  3. 按 Enter。

然后,您将需要更改 Binaries 目录。

  1. 键入 4,然后按 Enter。

  2. 输入 /usr/local/bin

  3. 按 Enter。

更改安装基础和二进制目录后,按 Enter 安装 PEAR。

对于系统范围的安装,您需要以增加的权限执行 go-pear 脚本。这仅推荐给高级用户。

<span style="color:#000000"><span style="background-color:#ffffff">       <strong><code>
$ curl -O https://pear.php.net/go-pear.phar
$ sudo php -d detect_unicode=0 go-pear.phar</code></strong></span></span>

现在检查 PEAR 是否有效。

托管环境中的 PEAR

如果您在无法直接访问服务器(通过本地登录、Telnet 或 SSH)的网络托管服务提供商处运行您的站点,您可以通过 Web 前端或(S)FTP使用 PEAR 安装程序 。

转到go-pear并另存为 go-pear.php. 复制go-pear.php到您的服务器并在浏览器中打开相应的 URL,例如http://example.com/pear/go-pear.php

如果您在安装前还没有这样做,请不要忘记保护 pear 目录:使其不可读且不可从外部执行(即,将其放在外部public_html)。

现在检查 PEAR 是否有效。

安装 pdo_mysql 扩展

could not find driver

错误显示为PDO没找到这个,tp5是用PDO连接数据库的,连接不上,那就安装呗

第一步:
在php的解压出来安装包里,一般进入到/usr/local/src/etc/pdo_mysql里。假设你的php是安装在/usr/local/php里的。执行/usr/local/php/bin/phpize

如果出现图上的红框,安装两个东西

安装完成后应该OK了

继续执行./configure –with-php-config=/usr/local/php/bin/php-config –with-pdo-mysql=/usr/local/mysql/ 第二个为mysql安装路径

执行完成,make编译一下,没问题继续make install

完成,会生成一个文件夹,里面有pdo_mysql.so这就是我们要的东西。
打印phpinfo()看一下extension_dir路径,有没有指向上面的路径

如果没有,打开php.ini修改,php.ini路径在这个页面上面

这里应该不用写绝对路径,但我还是谢了,确保这个路径下有pdo_mysql.so

忘了上面安装完可以运行看下/usr/local/php/bin/php -m有没有安装成功

Nice,之前我一安装到这里一直重启nginx好几次,还是没开启,原来php也要重启

关闭PHP
killall php-fpm

php重启
/usr/local/php/sbin/php-fpm &

关闭nginx
/usr/local/nginx/sbin/nginx -s stop //关闭服务器

开启nginx
/usr/local/nginx/sbin/nginx 开启服务器

重启nginx
/usr/local/nginx/sbin/nginx -s reload

OK,开启了,tp5也能正常访问了

如果src目录里面没有php安装包
直接下载pdo_mysql拓展源码包。下载页面在这里:http://pecl.php.net/package/PDO_MYSQL,可以先下载了然后用FTP传到服务器。
我是在复制了下载地址以后使用wget直接下载到服务器端的。
在/usr/local/src目录执行
wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz

然后解压
tar -zxvf PDO_MYSQL-1.0.2.tgz

进入解压后的目录,然后执行phpize,后面方法同上

这里放上一个测试pdo与的mysqli的demo

$pdo_startTime = microtime(true);

for($i=1;$i<=100;$i++){
    $pdo = new PDO("mysql:host=locahost;dbname=xf","root","root");
}

$pdo_endTime = microtime(true);

$pdo_time = $pdo_endTime - $pdo_startTime;
echo $pdo_time;
echo "<hr/>";

//通过mysql链接数据库
$mysqli_startTime = microtime(true);

for($i=1;$i<=100;$i++){
    mysqli_connect("host","username","123","xf");
}

$mysqli_endTime = microtime(true);

$mysqli_time = $mysqli_endTime - $mysqli_startTime;
echo $mysqli_time;

echo "<hr/>";

if($pdo_time > $mysqli_time){
    echo "pdo的连接时间是mysqli的".round($pdo_time/$mysqli_time)."倍";
}else{
    echo "mysqli的连接时间是pdo的".round($mysqli_time/$pdo_time)."倍";
}
————————————————
版权声明:本文为CSDN博主「机电爱迪生」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_42161963/article/details/80536283

之前讲配置文件和权限的时候有很多MySQL8的知识,有同志说安装不太一样,希望发个文,我这边简单演示一下

1.环境安装

下载MySQL提供的CentOS7的yum源

官方文档:<https://dev.mysql.com/doc/refman/8.0/en/>

过程中有不太懂的可以看我之前写的这篇文章:<http://www.cnblogs.com/dotnetcrazy/p/9887708.html>

地址:https://dev.mysql.com/downloads/repo/yum/

CentOS命令:curl https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm > centos7.mysql.rpm  下载yum源(curl是系统自带的)

安装yum源:yum install centos7.mysql.rpm -y

安装MySQL8.0 yum install mysql-community-server -y

启动mysql systemctl start mysqld

设置开机启动mysql systemctl enable mysqld

2.初始化配置

查看初始密码 cat /var/log/mysqld.log | grep "password"

安全初始化 mysql_secure_installation

3.权限设置

权限相关详细可以查看上次写的文章:聊聊数据库:SQL运维~存储引擎与权限

用root账号登录 mysql -uroot -p

创建用户dnt create user dnt@'%' identified by '含大小写字母+数字的密码';

查看当前有哪些用户 select user,authentication_string,host from mysql.user;

给用户dnt分配数据库dotnetcrazy的所有权限 grant all on dotnetcrazy.* to dnt;

刷新权限 flush privileges;

显示新用户有哪些权限 show grants for dnt;

4.配置相关

这块我就说下开远程的配置,其他的可以查看之前写的文章:<https://www.cnblogs.com/dotnetcrazy/p/10810798.html>

root权限去修改 /etc/my.cnf

[mysqld]选项下新增:bind-address=0.0.0.0

开放3306端口的远程访问权限:firewall-cmd --zone=public --add-port=3306/tcp --permanent

刷新防火墙规则 firewall-cmd --reload

重启MySQL:systemctl restart mysqld

测试

Shell附录

1.安装附录

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

# 下载yum源(curl是系统自带的)

# curl https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm > centos7.mysql.rpm

[root@localhost dnt] curl https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm > centos7.mysql.rpm

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

100 26024  100 26024    0     0  38150      0 --:--:-- --:--:-- --:--:-- 38158

[root@localhost dnt]# ls

centos7.mysql.rpm

# 安装MySQL的yum源

# yum install centos7.mysql.rpm -y

[root@localhost dnt] yum install centos7.mysql.rpm -y

已加载插件:fastestmirror

正在检查 centos7.mysql.rpm: mysql80-community-release-el7-3.noarch

centos7.mysql.rpm 将被安装

正在解决依赖关系

--> 正在检查事务

---> 软件包 mysql80-community-release.noarch.0.el7-3 将被 安装

--> 解决依赖关系完成

依赖关系解决

==========================================================================================================

 Package                                架构                版本                 源                           大小

==========================================================================================================

正在安装:

 mysql80-community-release              noarch              el7-3                /centos7.mysql               31 k

事务概要

==========================================================================================================

安装  1 软件包

总计:31 k

安装大小:31 k

Downloading packages:

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  正在安装    : mysql80-community-release-el7-3.noarch                                                         1/1

  验证中      : mysql80-community-release-el7-3.noarch                                                         1/1

已安装:

  mysql80-community-release.noarch 0:el7-3

完毕!

# 安装MySQL8.0

# yum install mysql-community-server -y

[root@localhost dnt] yum install mysql-community-server -y

已加载插件:fastestmirror

Loading mirror speeds from cached hostfile

 * base: mirrors.aliyun.com

 * extras: mirrors.cn99.com

 * updates: mirrors.aliyun.com

base                                                                                        | 3.6 kB  00:00:00

extras                                                                                      | 3.4 kB  00:00:00

mysql-connectors-community                                                                  | 2.5 kB  00:00:00

mysql-tools-community                                                                       | 2.5 kB  00:00:00

mysql80-community                                                                           | 2.5 kB  00:00:00

updates                                                                                     | 3.4 kB  00:00:00

(1/3): mysql-connectors-community/x86_64/primary_db                                         |  41 kB  00:00:00

(2/3): mysql80-community/x86_64/primary_db                                                  |  70 kB  00:00:00

(3/3): mysql-tools-community/x86_64/primary_db                                              |  58 kB  00:00:00

正在解决依赖关系

--> 正在检查事务

---> 软件包 mysql-community-server.x86_64.0.8.0.16-2.el7 将被 安装

--> 正在处理依赖关系 mysql-community-common(x86-64) = 8.0.16-2.el7,它被软件包 mysql-community-server-8.0.16-2.el7.x86_64 需要

--> 正在处理依赖关系 mysql-community-client(x86-64) >= 8.0.11,它被软件包 mysql-community-server-8.0.16-2.el7.x86_64 需要

--> 正在处理依赖关系 net-tools,它被软件包 mysql-community-server-8.0.16-2.el7.x86_64 需要

--> 正在检查事务

---> 软件包 mysql-community-client.x86_64.0.8.0.16-2.el7 将被 安装

--> 正在处理依赖关系 mysql-community-libs(x86-64) >= 8.0.11,它被软件包 mysql-community-client-8.0.16-2.el7.x86_64 需要

---> 软件包 mysql-community-common.x86_64.0.8.0.16-2.el7 将被 安装

---> 软件包 net-tools.x86_64.0.2.0-0.24.20131004git.el7 将被 安装

--> 正在检查事务

---> 软件包 mariadb-libs.x86_64.1.5.5.60-1.el7_5 将被 取代

--> 正在处理依赖关系 libmysqlclient.so.18()(64bit),它被软件包 2:postfix-2.10.1-7.el7.x86_64 需要

--> 正在处理依赖关系 libmysqlclient.so.18(libmysqlclient_18)(64bit),它被软件包 2:postfix-2.10.1-7.el7.x86_64 需要

---> 软件包 mysql-community-libs.x86_64.0.8.0.16-2.el7 将被 舍弃

--> 正在检查事务

---> 软件包 mysql-community-libs-compat.x86_64.0.8.0.16-2.el7 将被 舍弃

--> 解决依赖关系完成

依赖关系解决

==========================================================================================================

 Package                            架构          版本                              源                        大小

==========================================================================================================

正在安装:

 mysql-community-libs               x86_64        8.0.16-2.el7                      mysql80-community        3.0 M

      替换  mariadb-libs.x86_64 1:5.5.60-1.el7_5

 mysql-community-libs-compat        x86_64        8.0.16-2.el7                      mysql80-community        2.1 M

      替换  mariadb-libs.x86_64 1:5.5.60-1.el7_5

 mysql-community-server             x86_64        8.0.16-2.el7                      mysql80-community        403 M

为依赖而安装:

 mysql-community-client             x86_64        8.0.16-2.el7                      mysql80-community         32 M

 mysql-community-common             x86_64        8.0.16-2.el7                      mysql80-community        575 k

 net-tools                          x86_64        2.0-0.24.20131004git.el7          base                     306 k

事务概要

==========================================================================================================

安装  3 软件包 (+3 依赖软件包)

总下载量:441 M

Downloading packages:

警告:/var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-common-8.0.16-2.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY

mysql-community-common-8.0.16-2.el7.x86_64.rpm 的公钥尚未安装

(1/6): mysql-community-common-8.0.16-2.el7.x86_64.rpm                                       | 575 kB  00:00:00

(2/6): mysql-community-libs-8.0.16-2.el7.x86_64.rpm                                         | 3.0 MB  00:00:00

(3/6): mysql-community-libs-compat-8.0.16-2.el7.x86_64.rpm                                  | 2.1 MB  00:00:00

(4/6): net-tools-2.0-0.24.20131004git.el7.x86_64.rpm                                        | 306 kB  00:00:00

(5/6): mysql-community-client-8.0.16-2.el7.x86_64.rpm                                       |  32 MB  00:00:14

(6/6): mysql-community-server-8.0.16-2.el7.x86_64.rpm                                       | 403 MB  00:01:08

-------------------------------------------------------------------------------------------------------------------

总计                                                                               6.2 MB/s | 441 MB  00:01:10

从 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 检索密钥

导入 GPG key 0x5072E1F5:

 用户ID     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"

 指纹       : a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5

 软件包     : mysql80-community-release-el7-3.noarch (installed)

 来自       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  正在安装    : mysql-community-common-8.0.16-2.el7.x86_64                                                     1/7

  正在安装    : mysql-community-libs-8.0.16-2.el7.x86_64                                                       2/7

  正在安装    : mysql-community-client-8.0.16-2.el7.x86_64                                                     3/7

  正在安装    : net-tools-2.0-0.24.20131004git.el7.x86_64                                                      4/7

  正在安装    : mysql-community-server-8.0.16-2.el7.x86_64                                                     5/7

  正在安装    : mysql-community-libs-compat-8.0.16-2.el7.x86_64                                                6/7

  正在删除    : 1:mariadb-libs-5.5.60-1.el7_5.x86_64                                                           7/7

  验证中      : mysql-community-libs-8.0.16-2.el7.x86_64                                                       1/7

  验证中      : net-tools-2.0-0.24.20131004git.el7.x86_64                                                      2/7

  验证中      : mysql-community-libs-compat-8.0.16-2.el7.x86_64                                                3/7

  验证中      : mysql-community-client-8.0.16-2.el7.x86_64                                                     4/7

  验证中      : mysql-community-common-8.0.16-2.el7.x86_64                                                     5/7

  验证中      : mysql-community-server-8.0.16-2.el7.x86_64                                                     6/7

  验证中      : 1:mariadb-libs-5.5.60-1.el7_5.x86_64                                                           7/7

已安装:

  mysql-community-libs.x86_64 0:8.0.16-2.el7            mysql-community-libs-compat.x86_64 0:8.0.16-2.el7

  mysql-community-server.x86_64 0:8.0.16-2.el7

作为依赖被安装:

  mysql-community-client.x86_64 0:8.0.16-2.el7             mysql-community-common.x86_64 0:8.0.16-2.el7

  net-tools.x86_64 0:2.0-0.24.20131004git.el7

替代:

  mariadb-libs.x86_64 1:5.5.60-1.el7_5

完毕!

# 启动mysql

# systemctl start mysqld

[root@localhost dnt] systemctl start mysqld

[root@localhost dnt] pstree | grep mysql

        |-mysqld---37*[{mysqld}]

# 设置开机启动mysql

# systemctl enable mysqld

[root@localhost dnt] systemctl enable mysqld

[root@localhost dnt] reboot

Connection closing...Socket close.

Connection closed by foreign host.

Disconnected from remote host(MySQL_CentOS) at 10:56:42.

Connecting to 192.168.36.205:22...

Connection established.

To escape to local shell, press 'Ctrl+Alt+]'.

WARNING! The remote SSH server rejected X11 forwarding request.

Last login: Wed May 15 10:35:07 2019 from 192.168.36.144

[dnt@localhost ~]$ pstree | grep mysql

        |-mysqld---37*[{mysqld}]

# 查看mysql的状态

# systemctl status mysqld

[dnt@localhost ~]$ systemctl status mysqld

● mysqld.service - MySQL Server

   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)

   Active: active (running) since 三 2019-05-15 10:57:26 CST; 1min 3s ago

     Docs: man:mysqld(8)

           http://dev.mysql.com/doc/refman/en/using-systemd.html

  Process: 3934 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)

 Main PID: 3969 (mysqld)

   Status: "SERVER_OPERATING"

   CGroup: /system.slice/mysqld.service

           └─3969 /usr/sbin/mysqld

2.初始化配置附录

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

# 查看初始密码

# cat /var/log/mysqld.log | grep "password"

[dnt@localhost ~]$ cat /var/log/mysqld.log | grep "password"

2019-05-15T02:55:51.132377Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: wI>X.(tHE5&e

# 安全初始化

# mysql_secure_installation

[dnt@localhost ~]$ mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:

The 'validate_password' component is installed on the server.

The subsequent steps will run with the existing configuration

of the component.

Using existing password for root.

Estimated strength of the password: 100

Change the password for root ? ((Press y|Y for Yes, any other key for No) : n

 ... skipping.

By default, a MySQL installation has an anonymous user,

allowing anyone to log into MySQL without having to have

a user account created for them. This is intended only for

testing, and to make the installation go a bit smoother.

You should remove them before moving into a production

environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y

Success.

Normally, root should only be allowed to connect from

'localhost'. This ensures that someone cannot guess at

the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y

Success.

By default, MySQL comes with a database named 'test' that

anyone can access. This is also intended only for testing,

and should be removed before moving into a production

environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y

 - Dropping test database...

Success.

 - Removing privileges on test database...

Success.

Reloading the privilege tables will ensure that all changes

made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

Success.

All done!

3.权限附录

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

# 用root账号登录

# mysql -uroot -p

[dnt@localhost ~]$ mysql -uroot -p

Enter password:

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

Your MySQL connection id is 38

Server version: 8.0.16 MySQL Community Server - GPL

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.

# show databases;

mysql> show databases;

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

| Database           |

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

| information_schema |

| mysql              |

| performance_schema |

| sys                |

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

4 rows in set (0.00 sec)

# 创建用户dnt

# create user dnt@'%' identified by '含大小写字母+数字的密码';

mysql> create user dnt@'%' identified by '含大小写字母+数字的密码';

Query OK, 0 rows affected (0.06 sec)

# 查看当前有哪些用户

# select user,authentication_string,host from mysql.user;

mysql> select user,authentication_string,host from mysql.user;

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

| user             | authentication_string                                                  | host      |

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

| dnt              | $A$005$yOK}8VFp<    LE0BLBPFmeTy2vi8Q1JdmkhkPkaWBilxWYW2/jSsJ4OEa7B | %         |

| mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | localhost |

| mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | localhost |

| mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | localhost |

| root             | $A$005$yAn@!RwTRzRLdyRrHMdoneUh7pdKEJVFUl9LHdG5MHeL.gdovFMI7z22 | localhost |

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

5 rows in set (0.00 sec)

# 创建一个数据库

# create database dotnetcrazy charset=utf8;

mysql> create database dotnetcrazy charset=utf8;

Query OK, 1 row affected, 1 warning (0.71 sec)

mysql> show databases;

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

| Database           |

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

| dotnetcrazy        |

| information_schema |

| mysql              |

| performance_schema |

| sys                |

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

5 rows in set (0.00 sec)

# 给用户dnt分配数据库dotnetcrazy的所有权限

# grant all on dotnetcrazy.* to dnt;

mysql> grant all on dotnetcrazy.* to dnt;

Query OK, 0 rows affected (0.69 sec)

# 刷新权限

# flush privileges;

mysql> flush privileges;

Query OK, 0 rows affected (0.59 sec)

# 显示新用户有哪些权限

# show grants for dnt;

mysql> show grants for dnt;

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

| Grants for dnt@%                                     |

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

| GRANT USAGE ON *.* TO `dnt`@`%`                      |

| GRANT ALL PRIVILEGES ON `dotnetcrazy`.* TO `dnt`@`%` |

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

2 rows in set (0.00 sec)

mysql> exit

Bye

# 用新增用户登录

# mysql -udnt -p

[dnt@localhost ~]$ mysql -udnt -p

Enter password:

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

Your MySQL connection id is 39

Server version: 8.0.16 MySQL Community Server - GPL

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.

# show databases;

mysql> show databases;

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

| Database           |

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

| dotnetcrazy        |

| information_schema |

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

2 rows in set (0.01 sec)

4.配置附录

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

[dnt@localhost ~]$ su

密码:

[root@localhost dnt]# ls /etc/ | grep my

my.cnf

my.cnf.d

[root@localhost dnt]# ls /etc/my.cnf.d/

# 修改配置,运行远程登录

[root@localhost dnt]# vi /etc/my.cnf

[root@localhost dnt]# cat /etc/my.cnf

[mysqld]

bind-address=0.0.0.0 # 新增内容

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

# 查看一下防火墙状态

# systemctl status firewalld

[root@localhost dnt] systemctl status firewalld

● firewalld.service - firewalld - dynamic firewall daemon

   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)

   Active: active (running) since 三 2019-05-15 17:37:49 CST; 28min ago

     Docs: man:firewalld(1)

 Main PID: 3467 (firewalld)

   CGroup: /system.slice/firewalld.service

           └─3467 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

5月 15 17:37:47 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...

5月 15 17:37:49 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.

# 开放3306端口的远程访问权限

# firewall-cmd --zone=public --add-port=3306/tcp --permanent

[root@localhost dnt]# firewall-cmd --zone=public --add-port=3306/tcp --permanent

success

# 刷新防火墙规则

# firewall-cmd --reload

[root@localhost dnt]# firewall-cmd --reload

success

# 重启MySQL

# systemctl restart mysqld

[root@localhost dnt]# systemctl restart mysqld

CentOS7安装MySQL8.0和Nginx相关推荐

  1. centos7安装Mysql8.0步骤

    CentOS7安装mysql8.0步骤 1.1 安装前清理工作: 1.1.1 清理原有的mysql数据库: 使用以下命令查找出安装的mysql软件包和依赖包: rpm -pa | grep mysql ...

  2. Centos7 安装mysql8.0.21 Compressed TAR Archive版

    Centos7 安装mysql8.0.21 Compressed TAR Archive版 一.官网下载安装包https://downloads.mysql.com/archives/communit ...

  3. CentOS7安装MySQL8.0图文教程

    1.下载 MySQL 所需要的安装包 网址:https://dev.mysql.com/downloads/mysql/ 2.Select Operating System: 选择 Red Hat , ...

  4. centos7安装mysql8.0.31版本

    目录 1. 卸载mariadb 2. 下载 3. 安装 4. 修改/etc/my.cnf 5. 启动 6. 修改密码 1. 卸载mariadb 因centos7默认安装了mariadb, 会造成依赖冲 ...

  5. centos7安装mysql8.0简书_CentOS7安装MySQL8.0图文教程

    1.下载 MySQL 所需要的安装包 网址:https://dev.mysql.com/downloads/mysql/ 2.Select Operating System: 选择 Red Hat , ...

  6. centos7 安装mysql8.0超详细步骤

    一.进入安装目录 将账户切换到root账户下,进入local目录下 cd /usr/local 若当前目录下没有mysql,则新建一个mysql的目录,用于存放wget下载的rpm包. 切换到mysq ...

  7. CentOS7安装MySQL8.0

    一.配置yum源         1.下载mysql源安装包 wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch ...

  8. centos7安装mysql8.0简书_【Linux实战03】CentOS 7 下 MySQL 8.0 的安装

    一.安装前准备 1.查看当前服务器的发行版本号 2.查看当前服务器的内核版本 3.查看当前服务器的操作系统位数 ----温馨提示---- 为什么先做如上三个操作呢? 多数同学,部署各类软件不成功的原因 ...

  9. centos7安装MySql8.0.29教程

    个人名片: 对人间的热爱与歌颂,可抵岁月冗长

最新文章

  1. oracle10g索引不生效,oracle 10g分区表索引失效测试
  2. java --级联操作(查询/更新)
  3. 高速串行总线设计基础(四)眼图的形成原理
  4. 电脑如何下载python3-python3可以在哪里下载
  5. axios 请求的配置选项
  6. python 生成随机数_python 生成随机数模块random 常用方法总结
  7. php+错误+处理,PHP 错误处理手记!!!!!
  8. Deep Learning 【Nature review】
  9. python如果选择不在列表里_使用python中的in ,not in来检查元素是不是在列表中的方法...
  10. Cloudflare通过UnstoppableDomains添加对“.crypto”域名的支持
  11. 关于CVE-2020-14882,你需要知道的都在这里
  12. 针对binlog MIXED格式对表的增删改统计分析
  13. mysql语句中的注释方法_MySQL语句注释方式简介
  14. pytorch源码解析1——torch.optim:优化算法接口详解
  15. 百度php获取当前经纬度,百度地图获取经纬度的示例
  16. 强化学习读书笔记(一)
  17. RN:App版本更新提示方案
  18. 文本转语音TTS(文本阅读和视频配音制作)MP3
  19. centos8安装RabbitMQ和erlang
  20. windows中WinRAR命令行参数

热门文章

  1. 开启win10下Ubuntu子系统的SSH服务
  2. 计算机英语反思总结怎么写,英语考试反思总结(通用10篇)
  3. 如何利用origin提取原始数据
  4. Windows如何区分鼠标双击和两次单击
  5. 两个栈实现队列的push-pop操作---C++
  6. 箱线图(seaborn.boxplot)
  7. 高数【积分-定积分】--猴博士爱讲课
  8. 学交互设计要懂什么:交互设计师的知识体系
  9. python使用end报错
  10. fliqlo翻页时钟屏保win7/win10免费下载