PHP cannot connect to database PHP error can ' t connect to local MySQL server_mysql

Source: Internet
Author: User
Tags chmod php error
Test the PHP file
<?php
$link =mysql_connect (' localhost ', ' root ', ' zz ') or Die (Mysql_error ());
mysql_select_db (' test ') or Die (' no db ');
mysql_query (' SET NAMES utf8 ');
Echo 99;
?>
Error after run
Can ' t connect to the local MySQL server through socket '/tmp/mysql.sock '
But access to MySQL at the command line
[Root@localhost local]# mysql-u root-p
Enter Password:
Welcome to the MySQL Monitor. Commands End With; or \g.your MySQL connection ID is 3Server version:5.5.2-m2 Source distribution
Type ' help, ' or ' \h ' for help. Type ' \c ' to clear the buffer.
Mysql>
Solutions
Chown-r Root/usr/local/mysql
Chgrp-r Mysql/usr/local/mysql
Chown-r Root/usr/local/mysql/bin
Chgrp-r Mysql/usr/local/mysql/bin
Chgrp-r Mysql/var/lib/mysql
chmod 777/var/lib/mysql
Chown-r Root/var/lib/mysql/mysql
Chgrp-r Mysql/var/lib/mysql/mysql
chmod 777/var/lib/mysql/mysql
Chown-r root/var/lib/mysql/mysql/*
Chgrp-r mysql/var/lib/mysql/mysql/*
chmod 777/var/lib/mysql/mysql/*
chmod 777/usr/local/mysql/lib/mysql/libmysqlclient.a

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.