Showing posts with label phpMyAdmin. Show all posts
Showing posts with label phpMyAdmin. Show all posts

Monday, January 9, 2012

PhpMyAdmin Tutorial

Click here for Installation of phpMyAdmin Tutorials


You can access your MySQL account using phpMyAdmin using the link provided to you --something like below
http://localhost/phpmyadmin
When you click on the link above, a dialog box will prompt you for a username and password. This will be the username and password given you when we set  it up for you.

Login screen

Once you log in, a phpMyAdmin screen appears as shown below.

phpMyAdmin welcome page

Creating a table in your database

The left-hand frame in phpMyAdmin is used for navigation.You will see your database displayed here (in this case called mydomain). As you create tables, they will show below this.
Click on your database the navigation frame and a new window will appear on the right hand side.

Creating a table

We will create a table in the database, called "people". Use the Create new table feature. Type in the name of the new table into the Name: people, and the number of columns in the table (4) into Fields:. This tutorial is only designed to show you the basic php/MySQL/phpMyAdmin functions. You can delete it using the Drop function. You will want to allow for growth in your table.

Defining fields

Click Go and you should see something like this. The table title now appears with under the database name.

table features

Now enter the names and attributes of our table fields. Enter the following information as above:


Field Type Length Default
Extra
id int 6 0
auto_increment
name char 100

telephone char 50

birthday char 50



The Length value indicates the maximum allowable length of characters for input. There are many different values that can be set for Type; see further documentation here. The Types specified in this example aren't the most efficient, but just used for the purposes of this exercise. The "id" field, which will be used as a Primary key for this table, has been set to auto_increment, saving you from having to having to type in the next number in sequence when you input records.  Set the Default to 0
Once you've entered all the values, click Save. A screen like this will appear.

Table properties


Congratulations!-You have created your table! The corresponding SQL command for creating these fields is also displayed. This isn't needed but in time you will start to recognise MySql commands
Note that you can use Drop to delete a table or fields.
When you are ready we suggest you check out  all of the options on this page.
Inputting data into the table.
 Click the tab labeled "Insert" -  and another window should appear, like this.


Adding records


Now type in the details for each of the fields for this record. The "id" column was set to automatically increment so you do not need to enter a number.
Note - if you ever get lost with phpMyAdmin navigation  click "Home" in the left hand nav bar and start again.
Now click Save and the record is saved to the people table.
The previous window reappears with the SQL command for the insert. You can keep adding recordsby re-selecting Insert".
For multiple records, you can select the "Insert another new row" radio button on the input form.
When you've finished entering  several records into the table, you can check them by clicking on the  Browse tab. You can click on  individual records for editing or deleting.


browsing your table

You can use the Select tab to refine your display when your database starts grows to many pages of records.
Backup your data
You "don't know what you've got 'til its gone"!
- Click on your database name in the left hand navigation bar
- Click on EXPORT (top tab)
- Highlight the table/s you want to back up
- Select STRUCTURE and DATA radio button
- Select "Enclose table and field names with backquotes"
-  Select "Save as file" and "zipped" check boxes
- Click "Go" and a zipped archive file will be generated.
Well done! - you've created a database, a table and fields, entered in a few records, viewed the records, edited and perhaps deleted some of them and practised backing up.

Install phpMyAdmin on Linux


phpMyAdmin is a web-based tool written in PHP to manage the MySQL database. Apart from viewing the tables (and other db objects), you can perform lot of DBA functions through the web based interface. You can also execute any SQL query from the UI.



Installation  and configure of phpMyAdmin on Linux distributions.

1. phpMyAdmin Pre requisites

Make sure you have PHP 5 (or above) installed.

# php -v
PHP 5.3.2 (cli) (built: May 19 2010 03:43:49)
 
Make sure you have MySQL 5 (or above) installed.

# mysql -V
mysql  Ver 14.14 Distrib 5.1.47, for pc-linux-gnu (i686) using readline 5.1
 
Make sure Apache is installed and running.

PHP5 Modules

If you don’t have PHP, I recommend that you install PHP from source. Following is the configure command I executed while installing PHP from source. This includes all the required PHP modules for phpMyAdmin.

./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql --with-bz2 --with-zlib 
--enable-zip --enable-mbstring --with-mcrypt
  


If you don’t compile PHP5 with the above options, you’ll get following error message from phpMyAdmin web interface.
  • GZip – GZip compression and decompression requires functions (gzencode) which are unavailable on this system.
  • Bzip2 – Bzip2 compression and decompression requires functions (bzopen, bzcompress) which are unavailable on this system.
  • ZIP – Zip decompression requires functions (zip_open) which are unavailable on this system.
  • ZIP – Zip compression requires functions (gzcompress) which are unavailable on this system.

2. Download and Install phpmyadmin in Apache DocumentRoot

Identify your Apache’s DocumentRoot.


# grep DocumentRoot /usr/local/apache2/conf/httpd.conf
DocumentRoot /usr/local/apache2/htdocs



Download the latest version of phpMyAdmin
 

# cd /usr/local/apache2/htdocs

# tar xvfz phpMyAdmin-3.3.7-all-languages.tar.gz

# mv phpMyAdmin-3.3.7-all-languages phpmyadmin






3. Secure the phpmyadmin Directory – Create phpmy user

Create phpmy Unix user.

# adduser phpmy

# passwd phpmy
 
 
Check which user and group is used by Apache.

# egrep 'User|Group' /usr/local/apache2/conf/httpd.conf
User daemon
Group daemon
 
Modify the phpmyadmin directory’s user ownership to phpmy user.
# cd /usr/local/apache2/htdocs

# chown -R phpmy.daemon phpmyadmin/


4. Update phpMyAdmin config.inc from Wizard

You need to setup the config.inc file properly for phpMyAdmin to work. You can either create and edit this file manually, or use the config phpMyAdmin installer setup wizard. I recommend that you use the setup wizard, as it is very straight forward. To do that, you should create the following dummy config.inc with proper permission.


# cd /usr/local/apache2/htdocs/phpmyadmin/

# mkdir config

# chmod o+rw config

# cp config.sample.inc.php config/config.inc.php

# chmod o+w config/config.inc.php



Now, invoke the phpMyAdmin setup wizard from the browser using the 
URL: http://{your-ip-address}/phpmyadmin/setup/index.php . This will 
show the following setup wizard.






Click on “New Server”, which will display following server wizard.






Fill-out following information in the new server screen. Leave other fields to default values.
  • Verbose Name of the Server – Give some descriptive server name.
  • Password for Config Auth – Enter the MySQL root password here.
  • Authentication Type – The default selection is cookie. Just use that.
Click on Save to save the configuration. You might see following warning messages. Ignore it for now.
  • Use SSL – You should use SSL connections if your web server supports it
  • PHP extension to use – You should use mysqli for performance reasons
  • Blowfish secret – You didn’t have blowfish secret set and have enabled cookie authentication, so a key was automatically generated for you. It is used to encrypt cookies; you don’t need to remember it.

5. Launch phpmyadmin

Invoke phpMyAdmin from the browser using the URL: http://{your-ip-address}/phpmyadmin/index.php
If you’ve installed phpMyAdmin on a Linux desktop distribution, you can also access phpMyAdmin using the localhost URL: http://localhost/phpmyadmin/index.php
Login with your MySQL root password. i.e use “root” for phpmyadmin username. Use MySQL root’s password for phpmyadmin password.


If you see the “Cannot load mcrypt extension. Please check your PHP configuration.” message, you didn’t compile your PHP with mcrypt. Make sure you have libmcrypt and libmcrypt-devel packages installed on your Linux before you compile PHP with –with-mcrypt option.


You will also see the message : “Directory config, which is used by the setup script, still exists in your phpMyAdmin directory. You should remove it once phpMyAdmin has been configured.”
Just like the message says, remove the config directory.


# cd /usr/local/apache2/htdocs/phpmyadmin

# rm -rf config


After moving the config directory, if you go to setup/index.php url, you’ll see following message. This is a good thing, as you’ve already configured the phpMyAdmin.
“Cannot load or save configuration. Please create web server writable folder config in phpMyAdmin top level directory as described in documentation. Otherwise you will be only able to download or display it.”
Once you’ve logged-in you should be able to manage all the MySQL databases from your browser.