Computer Programming web Web programming Tips



How to use phpMyAdmin: Part 1

By Sergey Skudaev

In this tutorial you will learn how to use phpMyAdmin to manage MySQL database. How to create database, tables, how to alter table, add fields, insert records, backup table and backup database.

phpMyAdmin is an open source php script. Download phpMyAdmin from www.phpmyadmin.net and unzip it in "htdocs" directory.

On my PC it is C:\Apache\Apache2\htdocs. Start your browser and type in the Address:

http://localhost/phpMyAdmin/.

phpMyAdmin home page displays. Hover mouse over a thumbnail to see a large image.

phpMyAdmin home page



I got error message, because I forgot to start MySQL. I started MySQL and refreshed browser page. A new error message displays:

phpMyAdmin home page

The whole text in the message is:
phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in config.inc.php and make sure that they correspond to the information given by the administrator of the MySQL server.

Ok, let us open config.inc.php file and look at it contents. The config.inc.php file located in phpMyAdmin directory. Open the file in TextPad or Notepad and scroll down to Server Configuration.

/**
* Server(s) configuration
*/
$i = 0;
// The $cfg['Servers'] array starts with $cfg['Servers'][1]. Do not use $cfg['Servers'][0].
// You can disable a server config entry by setting host to '  '.
$i++;
$cfg['Servers'][$i]['host']          = 'localhost';       // MySQL hostname or IP address
$cfg['Servers'][$i]['port']          = '';                // MySQL port - leave blank for default port
$cfg['Servers'][$i]['socket']        = '';                // Path to the socket - leave blank for default socket
$cfg['Servers'][$i]['connect_type']  = 'tcp';          // How to connect to MySQL server ('tcp' or 'socket')
$cfg['Servers'][$i]['extension']     = 'mysql';     // The php MySQL extension to use ('mysql' or 'mysqli')
$cfg['Servers'][$i]['compress']      = FALSE;     // Use compressed protocol for the MySQL connection
                                                             // (requires PHP >= 4.3.0)
$cfg['Servers'][$i]['controluser']   = '';          // MySQL control user settings
                                                             // (this user must have read-only
$cfg['Servers'][$i]['controlpass'] = '';          // access to the "mysql/user"
                                                                 // and "mysql/db" tables).
                                                             // The controluser is also
                                                                 // used for all relational
                                                                 // features (pmadb)
$cfg['Servers'][$i]['auth_type']     = 'config';     // Authentication method (config, http or cookie based)?
$cfg['Servers'][$i]['user']          = 'root';          // MySQL user
$cfg['Servers'][$i]['password']      ='  ';          // MySQL password (only needed)

By default I had root user without password. To protect my database I set password aspirin. That is why phpMyAdmin cannot access my database. Since it is not good practice to use root user in php code let us created a new user.

Read One hour MySQL Tutorial to learn how to create users and set passwords to MySQL.

Login in MySQL as root user.

C:\mysql\bin>mysql -u root -paspirin
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 3.23.58-nt

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

Create a new user

mysql> GRANT ALL PRIVILEGES ON *.* TO 'sergeys'@'localhost' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.25 sec)

mysql>

Now type user name and password in Server Configuration

$cfg['Servers'][$i]['user']='sergeys'; // MySQL user
$cfg['Servers'][$i]['password']='password';// MySQL password (only needed)

Save file. Refresh browser page. phpMyAdmin home page displays:

phpMyAdmin home

Click Databases drop down list. The list of databases displays:

phpMyAdmin list of databases

Select your database and database tables (if any) display:

phpMyAdmin tables

>>Part 2>>


My eBooks on Amazon.com

Subscribe to our mail list to receive free code examples.

Comments

No comments yet.

Add Comment

* Required information
(never displayed)
 
Smile Sad Huh Laugh Mad Tongue Crying Grin Wink Scared Cool Sleep Blush Unsure Shocked
 
1000
What is the sum of 1 + 2 + 3?
 
Enter answer:
Captcha
Refresh
 
Enter code:
 
Notify me of new comments via email.
 
Remember my form inputs on this computer.
 
I have read and understand the privacy policy. *
 
I have read and agree to the terms and conditions. *
 
 
Powered by Commentics