Learn how to configure MySQL in Adobe Dreamweaver, create a MySQL database connection, and use MySQL utilities.

This document is applicable for Dreamweaver Creative Suite users with servers running PHP 5x.

If you are using Dreamweaver CC, refer to the following documents for information about database connections:

Overview

This document describes a few of the important factors involved in creating a successful MySQL database connection when using the PHP server model in Dreamweaver. It also covers some basic MySQL user account settings. It assumes that you have installed and configured MySQL on a local or remote computer.

Dreamweaver errors if setup is not completed correctly. A common error that can occur when testing a MySQL connection in Dreamweaver is "An unidentified error has occurred."

Note: This content provides a basic guide to getting started. To tailor the MySQL account settings to your specific security requirements, consult the MySQL documentation and other third-party resources. To download and install MySQL, visit the MySQL website.

MySQL configuration

The default installation of the MySQL database system contains two databases named mysql and test. The mysql database contains six tables that store information about privileges. This section discusses two of these tables: the user table and the db table.

The user table stores information about who can connect to the MySQL server and whether the user has any global level privileges. Because privileges in the user table affect all databases on the MySQL server, usually administrators will have some Ys (yes) in the privilege fields while most standard users have only Ns (no). The db table specifies the databases on the MySQL server that users are allowed to access, and this table is where most of the standard users' privileges are stored.

Note: Many third-party graphic interface utilities can help you visually manage MySQL databases; however, this document uses the native MySQL command-line client.

Whether you install MySQL on a UNIX, Windows, or Mac OS X machine, you can use the command prompt window to administer MySQL. In Windows, open the command prompt by choosing Start > Programs > Command Prompt. (On some systems, the Command Prompt may be located under Accessories in the Start > Programs menu.)

Change to the mysql\bin directory by entering the following commands at the command prompt:

> cd\> cd mysql\bin

During the MySQL installation, MySQL creates an account called root with no password, which you can use to log in to the database. Adobe highly recommends that you assign a password to this account since root has full control over the MySQL databases. To assign the root account a password, run the following command, which sets the root password to new-password. Replace new-password with a password of your choice that is more secure.

> mysqladmin -u root password new-password

Create separate MySQL accounts for each PHP web application. You can create as many MySQL accounts as you want and assign different rights and permissions to each account. Web application users do not need the same level of privileges as the root account.

To create a separate user account for your web application, connect to MySQL and log in with the superuser account using one of the following methods. In the example below, the account with superuser privileges is the root account. MySQL prompts you to enter a password when you press Enter:

> mysql --user=root --password

or

> mysql -uroot -p

Once logged in to MySQL, you will create a user called dbuser (the name is arbitrary) for the web application. Below are four examples of ways to set up this new user. In all four examples, a new user named dbuser is created. The four privileges granted to this user are SELECT, INSERT, UPDATE, and DELETE on any table in the employees database (this database is referred to as emp in the following examples). The password myPassword is encrypted in the MySQL database.

  • In this example, dbuser can only access the database from localhost:
    GRANT SELECT, INSERT, UPDATE, DELETE ON emp.* TO dbuser@localhost IDENTIFIED BY "myPassword";
  • In this example, dbuser can only access the database from mySite:
    GRANT SELECT, INSERT, UPDATE, DELETE ON emp.* TO dbuser@mySite IDENTIFIED BY "myPassword";
  • In this example, dbuser can only access the database from mySite.myDomain.com:
    GRANT SELECT, INSERT, UPDATE, DELETE ON emp.* TO dbuser@mySite.myDomain.com IDENTIFIED BY "myPassword";
  • In this example, dbuser can access the database from any host:
    GRANT SELECT, INSERT, UPDATE, DELETE ON emp.* TO dbuser@"%" IDENTIFIED BY "myPassword";

After running the GRANT statement(s), switch from the emp database back into the mysql database by running the following command:

>use mysql

To observe what changes have been made to the db table in the main mysql database, execute the following SQL statement:

SELECT Host, Db, User, Select_priv, Insert_priv,    Update_priv, Delete_priv   FROM db   WHERE User='dbuser';

Here is how the db table looks if you run all the GRANT statements listed above:

Host Db User Select_

priv
Insert_

priv
Update_

priv
Delete_

priv
localhost emp dbuser Y Y Y Y
mySite emp dbuser Y Y Y Y
mySite.

myDomain.com
emp dbuser Y Y Y Y
% emp dbuser Y Y Y Y

To observe what changes have been made to the user table in the main mysql database, execute the following SQL statement:

SELECT Host, User, Select_priv, Insert_priv,    Update_priv, Delete_priv   FROM user   WHERE User='dbuser';

Here is how the user table looks if you run all the GRANT statements above:

Host User Select_

priv
Insert_

priv
Update_

priv
Delete_

priv
localhost dbuser N N N N
mySite dbuser N N N N
mySite.

myDomain.com
dbuser N N N N
% dbuser N N N N

Note: For security purposes, do not modify the dbuser account in the user table unless the account needs administrative rights similar to the root or the MySQL administrator account. If you grant these privileges, the dbuser will have access to the system database.

MySQL automatically reads the user and db tables when it starts, and when GRANT and REVOKE statements are issued. If you make any manual changes to the user and db tables, reload the tables to process the changes using this command:

> flush privileges;

Setting up the PHP / MySQL site definition in Dreamweaver

A successful connection to a MySQL database in Dreamweaver depends on correct site definition entries when defining the site. Below is a sample PHP/MySQL site definition that uses a Linux PHP server running on a machine identified as mySite.myDomain.com. MySQL is running on another machine identified as mysql1.myDomain.com, and Dreamweaver is running on a local workstation. FTP is used to transfer files between the workstation and the Linux web server.

  • Local Info:
    • Site Name: mySite
    • Local Root Folder: C:\mySite\
  • Remote Info:
    • Access: FTP
    • FTP Host: mySite.myDomain.com
    • Host Directory: /htdocs/
    • Login: webadmin
    • Password: *********
  • Testing Server:
    • Server Model: PHP / MySQL
    • Access: FTP
    • FTP Host: mySite.myDomain.com
    • Host Directory: /htdocs/
    • Login: webadmin
    • Password: *********
    • URL Prefix: http://mySite.myDomain.com/

Create a MySQL database connection in Dreamweaver

Once you set up the MySQL user account and define the site, you can connect to your MySQL database in Dreamweaver. Using the above settings, here are example settings for the MySQL Connection dialog box in Dreamweaver:

Connection Name: Choose a name (such as connEmp)  
MySQL Server: mysql1.myDomain.com
User Name: dbuser
Password: myPassword
Database: Enter the name of your database or click Select to choose from a list of MySQL databases running on the server.

Note: For the MySQL Server field, you must enter localhost if PHP and MySQL are running on the same machine.

MySQL utilities

Third-party tools can help you configure and manage a MySQL database without having to know SQL. These tools are helpful if you prefer to work with databases through a visual interface rather than a command-line interface. You can download and install these tools on the machine running the MySQL database or the local workstation. Some popular tools include PHPMyAdminEMS MySQL Manager, urSQL, and PremiumSoft MySQL Studio.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy