简体   繁体   English

如何在 MacOS 上安装 MySQLi

[英]How to install MySQLi on MacOS

I cannot find instructions about installing MySQLi on a Mac.我找不到有关在 Mac 上安装 MySQLi 的说明。 Just to be clear, MySQL is up to date and I am running PHP 5. How do I install it?明确一点,MySQL 是最新的,我正在运行 PHP 5. 如何安装它? Where do I even get it from?我什至从哪里得到它? Thanks for your help.谢谢你的帮助。 I'll be giving an up vote and a check mark to whoever answers this!无论谁回答这个问题,我都会投赞成票并打勾!

Use php-mysqlnd instead of php-mysql .使用php-mysqlnd而不是php-mysql On Linux, to install with apt-get type:在 Linux 上,使用apt-get类型安装:

apt-get install php-mysqlnd

MySQLi is part of PHP. MySQLi 是 PHP 的一部分。 There should be a php-mysqli type package available, or you can take the PHP source and recompile that mysqli enabled.应该有一个 php-mysqli 类型的包可用,或者您可以使用 PHP 源代码并重新编译启用了 mysqli 的包。 You may already have it installed, but it's done as a module and is disabled.您可能已经安装了它,但它是作为一个模块完成的并且被禁用。 Check your php.ini for extension=mysqli.so or similar.检查您的 php.ini 是否有extension=mysqli.so或类似内容。 it may be commented out, or the .so file is present in your extensions directory but not linked to PHP via that extension= directive.它可能被注释掉,或者 .so 文件存在于您的扩展目录中,但未通过该 extension= 指令链接到 PHP。

This is how I installed it on my Debian based machine (ubuntu):这是我在基于 Debian 的机器 (ubuntu) 上安装它的方式:

php 7: php 7:

sudo apt-get install php7.0-mysqli

php 5: php 5:

sudo apt-get install php5-mysqli

This article is clearly explained, how to install MySqli with EachApache.这篇文章讲解的很清楚,如何用EachApache安装MySqli。 This works for me too.这也适用于我。

To install mysqli using EachApache:使用 EachApache 安装 mysqli:

  1. Login to WHM as 'root' user.以“root”用户身份登录 WHM。

  2. Either search for "EasyApache" or go to Software > EasyApache搜索“EasyApache”或转到“软件”>“EasyApache”

  3. Scroll down and select a build option (Previously Saved Config)向下滚动并选择一个构建选项(以前保存的配置)

  4. Click Start "Start customizing based on profile"单击开始“开始根据配置文件进行自定义”

  5. Select the version of Apache and click "Next Step".选择Apache的版本,然后单击“下一步”。

  6. Select the version of PHP and click "Next Step".选择 PHP 版本,然后单击“下一步”。

  7. Chose additional options within the "Short Options List"在“简短选项列表”中选择其他选项

  8. Select "Exhaustive Options List" and look for "MySQL Improved extension"选择“详尽的选项列表”并查找“MySQL改进的扩展”

  9. Click "Save and Build"点击“保存并构建”

You are supposed to edit two lines in your php.ini file (i'm using windows for this example):你应该在你的 php.ini 文件中编辑行(我在这个例子中使用的是 windows):

-The first one is regarding the extensions directory location. - 第一个是关于扩展目录位置。 See below:见下文:

; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "C:/php/ext"

-The second one is regarding the extension itself: - 第二个是关于扩展本身:

extension=php_mysqli.dll

Only modifying (uncommenting) the extension line was not enough for me.仅修改(取消注释)延长线对我来说是不够的。 Hope it helps希望能帮助到你

Here is the link for installation details: http://php.net/manual/en/mysqli.installation.php这是安装详细信息的链接: http : //php.net/manual/en/mysqli.installation.php

If you are using Windows or Linux :如果您使用的是WindowsLinux
- The MySQLi extension is automatically installed in most cases, when PHP & MySQL package is installed. - 在大多数情况下,当安装 PHP 和 MySQL 包时,MySQLi 扩展会自动安装。

For Windows: 3 steps对于 Windows:3 个步骤

Step1: Just need to give the ext folder path in php.ini Step1:只需要在php.ini给出ext文件夹路径即可

Here这里

; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
 extension_dir = "C:\php7\ext"

Step 2: Remove the comment from第二步:删除评论

extension=php_mysqli.dll

Step 3: restart the Apache server.第三步:重启Apache服务器。

Since you are using a Mac, open a terminal, and由于您使用的是 Mac,打开终端,然后

  • cd /etc光盘 / 等

Find the php.ini, and sudo open it, for example, using the nano editor找到php.ini,sudo打开,例如使用nano编辑器

  • nano php.ini纳米php.ini

Find use control+w to search for "mysqli.default_socket", and change the line to找到使用 control+w 搜索“mysqli.default_socket”,将这一行改为

  • mysqli.default_socket = /tmp/mysql.sock mysqli.default_socket = /tmp/mysql.sock

Use control+x and then hit "y" and "return" to save the file.使用 control+x 然后点击“y”和“return”来保存文件。 Restart Aapche if necessary.如有必要,重新启动 Aapche。

Now you should be able to run mysqli.现在您应该能够运行 mysqli。

I recently ditched Xampp in favor of the native Apache on Mac Sierra because a new php requirement of a project.我最近放弃了 Xampp,转而使用 Mac Sierra 上的本机 Apache,因为项目的新 php 要求。 Sierra comes with php 5.6.25, but it doesn't run mysql_* out of the box, after a lot of googling, I found this site really help - https://php-osx.liip.ch . Sierra 带有 php 5.6.25,但它并没有开箱即用地运行 mysql_*,经过大量的谷歌搜索,我发现这个站点真的很有帮助 - https://php-osx.liip.ch As it turns out php 5.6.25 does support mysql_* but wasn't enabled.事实证明 php 5.6.25 确实支持 mysql_* 但没有启用。 Choose your version of php and download it, it generates a proper php.ini for your php, then you are good to go选择你的php版本并下载它,它会为你的php生成一个合适的php.ini,然后你就可以开始了

sudo apt-get -y -f install php7.0-mysql

if you use ubuntu 16.04 (maybe and above) just do this如果您使用 ubuntu 16.04(可能及更高版本),请执行此操作

 sudo phpenmod mysqli
 sudo service php7.0-fpm restart

Since many of these answers are old here is how to install mysqli for Easyapache 4.由于这些答案中的许多都是旧的,因此这里是如何为 Easyapache 4 安装 mysqli。

If you try and search for mysqli under your PHP extensions in WHM you are not going to find it.如果您尝试在 WHM 中的 PHP 扩展下搜索 mysqli,您将找不到它。 The way to know which extension you need to install mysqli you will need to run this command in terminal知道需要安装 mysqli 的扩展的方法,您需要在终端中运行此命令

repoquery -q --whatprovides 'ea-php70-php-mysqli' | sort -V | tail -1

Should return something like应该返回类似的东西

ea-php70-php-mysqlnd-0:7.0.33-1.1.4.cpanel.x86_64

All you really need from this is mysqlnd copy it你真正需要的是mysqlnd复制它

To install mysqli using EachApache4:使用 EachApache4 安装 mysqli:

  • Login to WHM.登录 WHM。
  • Search for "EasyApache4"搜索“EasyApache4”
  • At the top look for "Currently Installed Packages" and click on the button "Customize"在顶部查找“当前安装的软件包”,然后单击“自定义”按钮
  • On the left panel click "PHP Extensions"在左侧面板上单击“PHP 扩展”
  • Search for mysqlnd搜索mysqlnd
  • You should see something like "php70-php-mysqlnd"您应该会看到类似“php70-php-mysqlnd”的内容
  • Toggle the switch to enable it切换开关以启用它
  • On the left panel click on review在左侧面板上单击评论
  • At the bottom click "Provision"在底部点击“提供”
  • You're Done你完成了

我遇到了同样的问题,我从 WHM 转到 EasyApache4,单击自定义按钮,然后单击 PHP 扩展选项卡。我选择并安装了扩展php72-php-mysqlnd ,我的问题解决了

Arch users (if using mariadb ) just should find the following line in /etc/php/php.ini and uncomment it. Arch用户 (如果使用mariadb )只需在/etc/php/php.ini找到以下行并将其取消注释即可。

extension=mysqli

https://wiki.archlinux.org/index.php/PHP#MySQL/MariaDB https://wiki.archlinux.org/index.php/PHP#MySQL/MariaDB

For mysqli on Docker's official php containers :对于 Docker 官方php 容器上的 mysqli:

Tagged php versions that support mysqli may still not come with mysqli configured out of the box, You can install it with the docker-php-ext-install utility (see comment by Konstantin).支持 mysqli 的标记 php 版本可能仍然没有配置开箱即用的 mysqli,您可以使用docker-php-ext-install实用程序安装它(请参阅 Konstantin 的评论)。 This is built-in, but also available from the docker-php-extension-installer project .这是内置的,但也可以从docker-php-extension-installer 项目获得

They can be used to add mysqli either in a Dockerfile, for example:它们可用于在 Dockerfile 中添加 mysqli,例如:

FROM php:5.6.5-apache
COPY ./php.ini /usr/local/etc/php/
RUN docker-php-ext-install mysqli

or in a compose file that uses a generic php container and then injects mysqli installation as a setup step into command :或者在使用通用 php 容器的撰写文件中,然后将 mysqli 安装作为设置步骤注入command

  web:
    image: php:5.6.5-apache
    volumes:
      - app:/var/www/html/
    ports:
      - "80:80"
    command:  >
      sh -c "docker-php-ext-install mysqli &&
             apache2-foreground"

这对我有用,可以运行这些命令:

sudo apt-get install php7.4-mysqli

sudo service apache2 restart

On php 5.3.0 and later version you dont need to specially install mysqli on windows.在 php 5.3.0 及更高版本上,您不需要在 Windows 上专门安装 mysqli。 Rather follow simple steps as shown below.而是按照如下所示的简单步骤操作。

Locate php.ini file [ if not there it means you have not copied php.ini-development or php.ini-production file as php.ini to make your configurations ]找到 php.ini 文件 [如果没有,则表示您尚未将 php.ini-development 或 php.ini-production 文件复制为 php.ini 来进行配置]

There are 2 things to be done 1. Uncomment and set right path to extension_dir = "ext" Basically set the path where you find ext folder in php even if its in same folder from where you are running php-cgi.ex有两件事要做 1. 取消注释并设置正确的路径 extension_dir = "ext" 基本上设置你在 php 中找到 ext 文件夹的路径,即使它在你运行 php-cgi.ex 的同一文件夹中

  1. uncomment mysqli library extention extension=mysqli取消注释 mysqli 库扩展 extension=mysqli

Note: uncommenting in this php.ini file is by removing starting ;注意:在这个 php.ini 文件中取消注释是通过删除开始; from the line.从线。

要解决此问题,您应该运行

sudo apt-get install php7.4-mysqli

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM