How to configure mysql in php in Windows/linux

Source: Internet
Author: User

Today, we will introduce the configuration of the apache environment. We will only introduce how to configure mysql in php so that your php can support mysql, if you have not configured a connection to the database, the following error occurs: Fatal error: Call to undefined function mysql_connect (). I will introduce it to you.

Window System Configuration mysql

Unable to connect to mysql. a PHP file for mysql testing is written as follows:

The Code is as follows: Copy code

<? Php $ link = mysql_connect ('localhost', 'root', 'root ');
If (! $ Link) echo "failed! ";
Else
Echo "successful! "; Mysql_close ();
?>

The error message is: Fatal error: Call to undefined function mysql_connect (). Obviously, the mysql database cannot be found. Baidu has a lot of errors, it is too complicated to copy mysql lib library and system32 directory to windows. In fact, the correct configuration should be in apache httpd. add the following settings to the conf file:

The Code is as follows: Copy code

LoadModule php5_module d:/tools/php-5.3.1/php5apache2_2.dll
AddType application/x-httpd-php. php
PHPIniDir d:/tools/php-5.3.1

Note that the last line is the key. Tell apache where your php configuration file is, or you have to copy the php. ini file to the windows System directory. Generally, we can use the configuration here to complete the combination of apache and php. In the php. ini file, you only need to modify the following:

# Modify the php extension library directory to your actual path

Extension_dir = "D:/tools/php-5.3.1/ext" # Remove the previous; extension = php_mysql.dll


Configure mysql in linux

First download the dmg installation package of MySql. In: http://dev.mysql.com/downloads/mysql/

Open the dmg file, which contains three installation items. Here, all three of them are installed, MySQLStartupItem. after pkg is installed, mysql will start automatically with the system startup, MySQL. prefPane indicates that you can see the mysql option in the system preference settings, and the installation item is mysql.

In this way, the installation is successful. Enable mysql in the system preference settings and enable the service. After installation, the default user name is root and the password is blank. For security, set a password.

Open the terminal. If you enter mysql to prompt that this command is not available, configure the environment variable in the mysql bin directory. Directory:/usr/local/mysql/bin/. Add it to the PATH variable. Here I will introduce another method,

Enter

The Code is as follows: Copy code

Sudo vim/etc/bashrc

Then add

The Code is as follows: Copy code

# Mysql
Alias mysql = '/usr/local/mysql/bin/mysql'
Alias mysqladmin = '/usr/local/mysql/bin/mysqladmin'

In this way, input mysql in the terminal has this command. In fact, it is a bit similar to the macro definition in C/C ++, and the role of Alias replacement.


Next, modify the root password. The command is as follows:

The Code is as follows: Copy code
Mysqladmin-uroot password 12345

In this way, the root password is changed to 12345.

Related Article

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.