This quickstart demonstrates how to connect to an Azure Database for MySQL using a PHP application. It shows how to use SQL statements to query, insert, update, and delete data in the database.
$ brew update && brew install mycli # Only on macOS or $ sudo apt-get install mycli # Only on debian or ubuntu Usage $ mycli -help Usage: mycli OPTIONS DATABASE A MySQL terminal client with auto-completion and syntax highlighting. Path to the kubeconfig file to use for CLI requests.-log-backtrace-at traceLocation Default::0: when logging hits line file:N, emit a stack trace-log-dir string: If non-empty, write log files in this directory-log-file string: If non-empty, use this log file-log-file-max-size uint Default: 1800: Defines the maximum size a log file can grow to. On macOS, this can be achieved by opening the downloaded.tar.gz archive file in the preferred location. If you would like to replace an existing installation, remove the existing google-cloud-sdk directory and extract the archive to the same location. Oct 28, 2020 Create an Azure Database for MySQL single server using Azure portal or Azure CLI if you do not have one. Based on whether you are using public or private access, complete ONE of the actions below to enable connectivity.
For this quickstart you need:
An Azure account with an active subscription. Create an account for free.
Create an Azure Database for MySQL single server using Azure portal
or Azure CLI if you do not have one.
Based on whether you are using public or private access, complete ONE of the actions below to enable connectivity.
Action | Connectivity method | How-to guide |
---|---|---|
Configure firewall rules | Public | Portal CLI |
Configure Service Endpoint | Public | Portal CLI |
Configure private link | Private | Portal CLI |
Install latest PHP version for your operating system
Note
We are using MySQLi library to manage connect and query the server in this quickstart.
You can get the database server connection information from the Azure portal by following these steps:
Log in to the Azure portal.
Navigate to the Azure Databases for MySQL page. You can search for and select Azure Database for MySQL.
Select your MySQL server (such as mydemoserver).
In the Overview page, copy the fully qualified server name next to Server name and the admin user name next to Server admin login name. To copy the server name or host name, hover over it and select the Copy icon.
Important
SSL is enabled by default. You may need to download the DigiCertGlobalRootG2 SSL certificate to connect from your local environment. This code calls:
Use the following code to connect. This code calls:
Use the following code to insert data by using an INSERT SQL statement. This code uses the methods:
Use the following code to read the data by using a SELECT SQL statement. The code uses the method:
Use the following code delete rows by using a DELETE SQL statement. The code uses the methods:
To clean up all resources used during this quickstart, delete the resource group using the following command:
Manage Azure Database for MySQL server using Portal
We value the diversity of our community. We strive to amplify the voices of the oppressed to eradicate racism and xenophobia. We ask our community to stand together in support of the Black community.
MyCLI is a command line interface for MySQL, MariaDB, and Percona with auto-completion and syntaxhighlighting.
If you already know how to install python packages, then you can simply do:
If you're on macOS you can install it via homebrew.
If you're having trouble with the quick start, check the install page fordetailed instructions.