MySQL and PHP are two tools commonly used in website development. MySQL is an open source relational database management system, and PHP is a widely used server-side scripting language. In this article, we will discuss how to install MySQL and PHP, and how to connect them.
Installing MySQL
MySQL has versions for mainstream operating systems such as Windows, Linux and Mac OS X. Below we will introduce how to install MySQL on these operating systems one by one.
Installing MySQL on Windows
The following are the steps to install MySQL on Windows:
- Download the MSI installation file from the MySQL official website.
- Double-click the downloaded installation file to start the installation process.
- Select "Custom" on the installation interface, and then click "Next".
- Click "Execute" to run the installer.
- Select the "Server only" option and click "Next".
- Select the path to the MySQL installation and the location of the data folder, and click "Next".
- On the "Configure MySQL Server" page, you can select a service name and port number.
- In the "Type and Networking" page, select the "Development Machine" option and enable the TCP/IP protocol.
- In the "Authentication Method" interface, select the "Use Strong Password Encryption" option.
- In the "Complete the MySQL Server Configuration Wizard" page, select the "Install As a Windows Service" option and configure MySQL to start automatically.
- Enter the password of the root user of your choice and click "Finish" to complete the configuration wizard.
Installing MySQL on Ubuntu
Here are the steps to install MySQL on Ubuntu:
- Open the terminal and enter the following command:
sudo apt-get update && sudo apt-get upgrade
Copy after login
- Enter the following command to install MySQL:
sudo apt-get install mysql-server
Copy after login
- During the installation process, you will be asked to enter the password of the MySQL root user. Confirm the password after the installation process will continue.
- After the installation is complete, enter the following command to check whether the MySQL service is running:
sudo systemctl status mysql
Copy after login
Installing MySQL on Mac OS Steps to install MySQL:
Download the dmg file from the MySQL official website.
- Double-click the downloaded installation file and connect to the dmg file.
- Double-click the "mysql-xxx.pkg" file to start the installation process.
- Read the installation wizard and click "Continue".
- Click "Agree" to accept the license agreement.
- Perform the installation process and enter the administrator password.
- In the "Select a Setup Type" interface, select the "Custom" option and make sure MySQL Server is selected.
- Click "Install".
- After the installation is complete, you will be asked to enter the password of the MySQL root user.
- Connecting MySQL and PHP
Once you have successfully installed MySQL and PHP on your system, you need to ensure that they are connected correctly. Here are a few steps:
Open the php.ini file and add the following statements to the end of the file:
extension=mysql.so
Copy after login
Add the MySQL username and password into the mysql_connect function in your PHP code. For example:
$mysql_connection = mysql_connect("localhost", "root", "password");
Copy after login
In phpMyAdmin or the MySQL command line, create a new database.
- Add the database name from your PHP code to the mysql_select_db function. For example:
mysql_select_db("database_name",$mysql_connection);
Copy after login
In your PHP code, use the mysql_query function to execute a MySQL query.
- Summary
MySQL and PHP, both tools are very important components in website development. Whether you're working on Windows, Linux, or Mac, you can install and connect both tools using the detailed steps provided in this article. As long as you connect these two tools correctly, you can use a MySQL database on your website and use PHP to control the loading and display of data.
The above is the detailed content of Discuss how to install MySQL and PHP (steps). For more information, please follow other related articles on the PHP Chinese website!