Home >Backend Development >PHP Problem >Discuss how to install MySQL and PHP (steps)

Discuss how to install MySQL and PHP (steps)

PHPz
PHPzOriginal
2023-04-12 09:20:20760browse

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:

  1. Download the MSI installation file from the MySQL official website.
  2. Double-click the downloaded installation file to start the installation process.
  3. Select "Custom" on the installation interface, and then click "Next".
  4. Click "Execute" to run the installer.
  5. Select the "Server only" option and click "Next".
  6. Select the path to the MySQL installation and the location of the data folder, and click "Next".
  7. On the "Configure MySQL Server" page, you can select a service name and port number.
  8. In the "Type and Networking" page, select the "Development Machine" option and enable the TCP/IP protocol.
  9. In the "Authentication Method" interface, select the "Use Strong Password Encryption" option.
  10. In the "Complete the MySQL Server Configuration Wizard" page, select the "Install As a Windows Service" option and configure MySQL to start automatically.
  11. 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:

  1. Open the terminal and enter the following command:
sudo apt-get update && sudo apt-get upgrade
  1. Enter the following command to install MySQL:
sudo apt-get install mysql-server
  1. 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.
  2. After the installation is complete, enter the following command to check whether the MySQL service is running:
sudo systemctl status mysql

Installing MySQL on Mac OS Steps to install MySQL:

Download the dmg file from the MySQL official website.
  1. Double-click the downloaded installation file and connect to the dmg file.
  2. Double-click the "mysql-xxx.pkg" file to start the installation process.
  3. Read the installation wizard and click "Continue".
  4. Click "Agree" to accept the license agreement.
  5. Perform the installation process and enter the administrator password.
  6. In the "Select a Setup Type" interface, select the "Custom" option and make sure MySQL Server is selected.
  7. Click "Install".
  8. After the installation is complete, you will be asked to enter the password of the MySQL root user.
  9. 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:
  1. extension=mysql.so
Add the MySQL username and password into the mysql_connect function in your PHP code. For example:
  1. $mysql_connection = mysql_connect("localhost", "root", "password");
In phpMyAdmin or the MySQL command line, create a new database.
  1. Add the database name from your PHP code to the mysql_select_db function. For example:
  2. mysql_select_db("database_name",$mysql_connection);
In your PHP code, use the mysql_query function to execute a MySQL query.
  1. 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn