如何在PHP7中安装mysql的扩展
2022-07-28 15:20:24
129
{{single.collect_count}}

相对与PHP5,PHP7的最大变化之一是移除了mysql扩展,推荐使用mysqli或者pdo_mysql,实际上在PHP5.5开始,PHP就着手开始准备弃用mysql扩展,如果你使用mysql扩展,可能看到过这样的提示”Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in”.所以在以后的程序中,为了保持兼容性,要尽量减少使用mysql扩展用于数据库连接.

作为运维人员来说,既想使用PHP7来提升服务器的效率,又要保证老的程序能够运行,如何做呢?

1.去php网站上下载mysql扩展,http://git.php.net/?p=pecl/database/mysql.git;a=summary

2.解压并使用phpize工具初始化,编译:

  1. #解压   
  2. tar xzvf mysql-45881bd.tar.gz   
  3. #进入mysql扩展目录  from www.mfbuluo.com   
  4. cd mysql-45881bd/    
  5. #使用phpize初始化,我的phpize在/opt/目录   
  6. /opt/php/bin/phpize   
  7. #编译mysql扩展,使用mysql native driver作为mysql链接库   
  8. ./configure --with-php-config=/opt/php/bin/php-config --with-mysql=mysqlnd   
  9. make && make install  

3.接下来,我们直接编辑php.ini文件,把mysql.so拷贝到php.ini的extension_dir中,然后在php.ini中加入extension=mysql.so

4.重启php

成功之后,用phpinfo即可看到mysql扩展的信息:

小结

相对于PHP5,都说PHP7有非常大的性能提升.如果您还在使用其它版本,可以升级一下试试.

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}