How to Use MySQL

Overview

MySQL is a very fast, multi-threaded, multi-user, and robust SQL (Structured Query Language) database server.

Path to MySQL:
/usr/local/mysql

Connecting to MySQL through PERL using the mySQLPerl Module

Use the following outline to connect and begin querying the mySQL server from a Perl script. Remember that you cannot connect to your databases remotely due to security concerns, you can only connect from localhost.

1. Declarations

You must require the mySQL package for your script to function properly. Do this by including the following line in your code: use Mysql;

2. Connect To The Database

Somewhere near the beginning of your script, you need to make your initial connection to the database server. Using the following form, substitute your database, username, and password for the examples to connect succesfully. The database must be a valid one that you have created through the MyAdmin interface. The username must be one created in MyAdmin with adequate permissions to the specified database.

Mysql->connect('localhost','DATABASENAME','USERNAME','USERPASSWORD');

3. Executing A Query

You are now ready to begin querying the database server. Most problems that you may incur will generally occur due to invalid permission settings for the specified user. Remember that you can use our convienent web based MyAdmin interface to view or edit these settings.

Connecting to mySQL through PHP

Use the following outline to connect and begin querying the mySQL server from within your PHP scripts. Remember that you cannot connect to your databases remotely due to security reasons. You can only connect to them form localhost.

1. Connect To The mySQL Server

Use the following statement to connect to the database server. Substitute the username, and password for ones who have created in the MyAdmin interface and have given adequate permissions to this database.

MYSQL_CONNECT('localhost','USERNAME','PASSWORD');

2. Select Your Database

Use the following statement to select the database you wish to connect to. Make sure you substitute the example with your database name.

@mysql_select_db("DATABASENAME");

3. Executing A Query

You are now ready to execute your queries. Most problems that arise with your scripts will be due to incorrect permission settings.

Connecting to MySQL with JSP

If you are using MySQL with JSP, ie. our Tomcat hosting, you will need the Class.forName path to the MySQL Driver:

Class.forName("com.mysql.JDBC.Driver").newInstance()

To test your connection:

Class.forName("com.mysql.jdbc.Driver").newInstance();
java.sql.Connection conn;
conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/dbname?user=blah&password=blah");

phpMyAdmin

It is a web-based program that allows you to work with the MySQL database with out having to use or know unix command line. You can add and delete databases, tables and data contained in those tables.

Currently phpMyAdmin can:

  • create and drop databases
  • create, copy, drop and alter tables
  • delete, edit and add fields
  • execute any SQL-statement, even batch-queries
  • manage keys on fields
  • load text files into tables
  • create (*) and read dumps of tables
  • export (*) and import data to CSV values
  • administer multiple servers and single databases
  • communicate in more than 20 different languages

To access MySQL with phpMyAdmin click on Services in the left pane, then the pencil for MySQL service. Then you will have a link "MySQL Administration Tool" clicking on that brings up a new window to allow you to log into your database where you can setup tables using a web browser.

  • 152 Users Found This Useful
Was this answer helpful?

Related Articles

PostgreSQL

What Is PostgreSQL? PostgreSQL is pronounced Post-Gres-Q-L, also called just Postgres....

Connecting to MySQL Remotely

You can connect to MySQL remotely by using host % instead of localhost. If you are security...

How to Install Oracle XE 11g on CentOs 5

 Note: # means ROOT prompt. # yum install libaio bc flex Download...

The Most Important MySQL Commands

How to setup MySQL a database, a user, and then import SQL data. 1- SSH into server # mysql -u...

How to create database in Siteworx

How to create a database in siteworx With Sitworx UI you have full control over the creation of...