PHP connection to MySQL database under Mac failure solution

Source: Internet
Author: User

MySQL was successfully connected via phpMyAdmin, but failed to connect to the database via PHP, execute the following PHP statement

?
1 @mysql_connect("localhost","root","12345") ordie("数据库服务器连接失败");// 连接服务器

After that, the browser output database server connection failed with the workaround below.

1, the MySQL installation path for Mac, * for the version number, is the number.

?
1 /usr/local/mysql_******_osx10.*_x86_64

2, enter this folder after the bin to find the MySQL, double-click Open, double-tap does not open the choice of terminal Open, and then enter

?
1 STATUS

Find the value of the UNIX socket after carriage return

3. Find PHP.ini, find/etc/php.ini in Finder, copy to desktop, open with document, press and hold command+f, then find pdo_mysql.default_socket, Mysql.default_socket, Mysqli.default_socket These three values, changed to the UNIX socket above the value, modified to copy to just the folder, replace the previous file

4, open the terminal, input sudo apachectl restart restart Apache can, again execute will not error

PHP connection to MySQL database under Mac failure solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.