Skip to content
Hosting Manual
  • Hosting Reviews
    • Bluehost Review
    • GreenGeeks Review
    • Inmotion Hosting Review
    • iPage Review
  • SLA & Uptime Calculator
  • Services
    • WordPress Migration Service
    • WordPress SEO Optimization
    • WordPress Speed Optimization
  • Domain Search

Introduction to MySQL

You can create various number of MySQL databases depending on your host using the “Add MySQL Database” function of your Control Panel. Please note that most web hosts do not provide any support related to the use of this complex application beyond the information provided on this page. For more information, please visit the MySQL Home Page.

At some providers your MySQL USERNAME is your domain name without the extension (e.g., if your domain name is fred.com, your MySQL USERNAME is: fred.) MySQL truncates usernames to 16 characters, so if your domain name is longer than 16 characters, just use the first 16 (e.g., the USERNAME for ihaveanincrediblylongdomainname.com would be: ihaveanincredibl.)

Accessing MySQL

Use the following outline to connect and begin querying the mySQL server.

Connect to the mySQL Server

servername:> mysql -u USERNAME -p 

Connect to the Database

mysql> use DATABASENAME;

Receiving Help

mysql> help

Accessing MySQL with the MySQL Perl Module

Use the following outline to connect and begin querying the mySQL server from a Perl script.

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;

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 successfully.

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

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.]

Accessing MySQL with 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.

Connect to the mySQL Server: Use the following statement to connect to the database server. Substitute the username, and password for ones you have created.

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

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");

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.)

Export (Dump) or Backup your MySQL Database

To create a backup (dump) of your MySQL database through shell: Connect via SSH, navigate to the directory in which you want your backup stored, and issue the following command:

mysqldump -uusername -ppassword dbname > file.txt

(where username is your MySQL username; password is your MySQL password; dbname is the name of your database; and file.txt is the name of your backup file.)

Import / Restore your MySQL Database

To import/restore your database from an existing backup: Connect via SSH, navigate to the directory that contains your backup, and issue the following command:

mysql -uusername -ppassword dbname < file.txt

(where username is your MySQL username; password is your MySQL password; dbname is the name of your database; and file.txt is the name of your backup file.)

  • A Complete Introduction to Email Marketing
  • Publishing Your Website: Go-Live Checklist
  • 9 Web Hosting Mistakes You Don’t Want to Make
  • How to Make a Website on a Budget with Wordpre
  • How much Bandwidth and Disk Space do I need?
  • How to Choose the Perfect Domain Name
  • How to Speed Up Any Website (Especially WordPress)
  • Robots.txt File Explained: Allow or Disallow All or Part of Your Website
  • Understanding the Domain Name System
  • How to Fix Broken Images and Links on Your Website
Bluehost Special

 

Disclosure: This is an affiliate link. You can support us by clicking on it and buying web hosting.

HostingManual.net · Contact · Terms of Service · Affiliate Disclaimer · Review Policy · Sitemap (xml)

© 2023 Hosting Manual
  • Hosting Reviews
    • Bluehost Review
    • GreenGeeks Review
    • Inmotion Hosting Review
    • iPage Review
  • SLA & Uptime Calculator
  • Services
    • WordPress Migration Service
    • WordPress SEO Optimization
    • WordPress Speed Optimization
  • Domain Search