如何安裝使用PHP MyAdmin

前言:php

  由於工做的緣由,不少地方須要用到數據庫查詢,爲了不破壞真實存在的數據庫,因此,我搭建了一個虛擬機,在搭建的虛擬機上將數據庫進行了導入。這裏,用了一個PHP myAdmin的工具,我的以爲仍是很是方便控制管理數據庫的。故作了下研究,寫下此文章記錄下。html

 

PHP myAdmin簡介mysql

phpMyAdmin 是一個以 PHP爲基礎,以Web-Base方式架構在網站主機上的 MySQL的數據庫管理工具,讓管理者可用Web接口管理MySQL數據庫。藉由此Web接口能夠成爲一個簡易方式輸入繁雜SQL語法的較佳途徑,尤爲要處理大量資料的匯入及匯出更爲方便。其中一個更大的優點在於因爲phpMyAdmin跟其餘PHP程式同樣在網頁服務器上執行,可是您能夠在任何地方使用這些程式產生的 HTML頁面,也就是於遠端管理MySQL數據庫,方便的創建、修改、刪除數據庫及資料表。也可藉由phpMyAdmin創建經常使用的php語法,方便編寫網頁時所須要的sql語法正確性。
 
具體安裝步驟:
 
1.安裝mysql
若是你的服務器上安裝配置好了yum源的話,一切都變了簡單了,具體操做執行命令以下:
1) 安裝軟件

root@cent42:/var/www/html> yum install mysql-serversql

Loaded plugins: fastestmirror數據庫

Setting up Install Process瀏覽器

Loading mirror speeds from cached hostfile安全

Resolving Dependencies服務器

--> Running transaction check架構

---> Package mysql-server.i686 0:5.1.73-5.el6_6 will be installedtcp

--> Processing Dependency: mysql = 5.1.73-5.el6_6 for package: mysql-server-5.1.73-5.el6_6.i686

--> Processing Dependency: perl-DBI for package: mysql-server-5.1.73-5.el6_6.i686

--> Processing Dependency: perl-DBD-MySQL for package: mysql-server-5.1.73-5.el6_6.i686

--> Processing Dependency: perl(vars) for package: mysql-server-5.1.73-5.el6_6.i686

--> Processing Dependency: perl(strict) for package: mysql-server-5.1.73-5.el6_6.i686

--> Processing Dependency: perl(Sys::Hostname) for package: mysql-server-5.1.73-5.el6_6.i686

--> Processing Dependency: perl(POSIX) for package: mysql-server-5.1.73-5.el6_6.i686

--> Processing Dependency: perl(Getopt::Long) for package: mysql-server-5.1.73-5.el6_6.i686

--> Processing Dependency: perl(File::Temp) for package: mysql-server-5.1.73-5.el6_6.i686

--> Processing Dependency: perl(File::Path) for package: mysql-server-5.1.73-5.el6_6.i686

--> Processing Dependency: perl(File::Copy) for package: mysql-server-5.1.73-5.el6_6.i686

--> Processing Dependency: perl(File::Basename) for package: mysql-server-5.1.73-5.el6_6.i686

--> Processing Dependency: perl(Data::Dumper) for package: mysql-server-5.1.73-5.el6_6.i686

--> Processing Dependency: perl(DBI) for package: mysql-server-5.1.73-5.el6_6.i686

--> Processing Dependency: /usr/bin/perl for package: mysql-server-5.1.73-5.el6_6.i686

--> Running transaction check

---> Package mysql.i686 0:5.1.73-5.el6_6 will be installed

---> Package perl.i686 4:5.10.1-141.el6 will be installed

--> Processing Dependency: perl-libs = 4:5.10.1-141.el6 for package: 4:perl-5.10.1-141.el6.i686

--> Processing Dependency: perl-libs for package: 4:perl-5.10.1-141.el6.i686

--> Processing Dependency: perl(version) for package: 4:perl-5.10.1-141.el6.i686

--> Processing Dependency: perl(Pod::Simple) for package: 4:perl-5.10.1-141.el6.i686

--> Processing Dependency: perl(Module::Pluggable) for package: 4:perl-5.10.1-141.el6.i686

--> Processing Dependency: libperl.so for package: 4:perl-5.10.1-141.el6.i686

---> Package perl-DBD-MySQL.i686 0:4.013-3.el6 will be installed

---> Package perl-DBI.i686 0:1.609-4.el6 will be installed

--> Running transaction check

---> Package perl-Module-Pluggable.i686 1:3.90-141.el6 will be installed

---> Package perl-Pod-Simple.i686 1:3.13-141.el6 will be installed

--> Processing Dependency: perl(Pod::Escapes) >= 1.04 for package: 1:perl-Pod-Simple-3.13-141.el6.i686

---> Package perl-libs.i686 4:5.10.1-141.el6 will be installed

---> Package perl-version.i686 3:0.77-141.el6 will be installed

--> Running transaction check

---> Package perl-Pod-Escapes.i686 1:1.04-141.el6 will be installed

--> Finished Dependency Resolution

 

Dependencies Resolved

 

=================================================================================================================

 Package                            Arch              Version                       Repository              Size

=================================================================================================================

Installing:

 mysql-server                       i686              5.1.73-5.el6_6                c6-xiawei              8.8 M

Installing for dependencies:

 mysql                              i686              5.1.73-5.el6_6                c6-xiawei              904 k

 perl                               i686              4:5.10.1-141.el6              c6-xiawei              9.7 M

 perl-DBD-MySQL                     i686              4.013-3.el6                   c6-xiawei              134 k

 perl-DBI                           i686              1.609-4.el6                   c6-xiawei              705 k

 perl-Module-Pluggable              i686              1:3.90-141.el6                c6-xiawei               40 k

 perl-Pod-Escapes                   i686              1:1.04-141.el6                c6-xiawei               33 k

 perl-Pod-Simple                    i686              1:3.13-141.el6                c6-xiawei              213 k

 perl-libs                          i686              4:5.10.1-141.el6              c6-xiawei              594 k

 perl-version                       i686              3:0.77-141.el6                c6-xiawei               52 k

 

Transaction Summary

=================================================================================================================

Install      10 Package(s)

 

Total download size: 21 M

Installed size: 59 M

Is this ok [y/N]: y

Downloading Packages:

(1/10): mysql-5.1.73-5.el6_6.i686.rpm                                                     | 904 kB     00:00    

(2/10): mysql-server-5.1.73-5.el6_6.i686.rpm                                              | 8.8 MB     00:00    

(3/10): perl-libs-5.10.1-141.el6.i686.rpm                                                 | 594 kB     00:00    

(4/10): perl-DBD-MySQL-4.013-3.el6.i686.rpm                                               | 134 kB     00:00    

(5/10): perl-Pod-Escapes-1.04-141.el6.i686.rpm                                            |  33 kB     00:00    

(6/10): perl-Pod-Simple-3.13-141.el6.i686.rpm                                             | 213 kB     00:00    

(7/10): perl-DBI-1.609-4.el6.i686.rpm                                                     | 705 kB     00:00    

(8/10): perl-Module-Pluggable-3.90-141.el6.i686.rpm                                       |  40 kB     00:00    

(9/10): perl-version-0.77-141.el6.i686.rpm                                                |  52 kB     00:00    

(10/10): perl-5.10.1-141.el6.i686.rpm                                                     | 9.7 MB     00:00    

-----------------------------------------------------------------------------------------------------------------

Total                                                                             24 MB/s |  21 MB     00:00    

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Running Transaction

  Installing : 1:perl-Pod-Escapes-1.04-141.el6.i686                                                         1/10

  Installing : 1:perl-Pod-Simple-3.13-141.el6.i686                                                          2/10

  Installing : 1:perl-Module-Pluggable-3.90-141.el6.i686                                                    3/10

  Installing : 3:perl-version-0.77-141.el6.i686                                                             4/10

  Installing : 4:perl-libs-5.10.1-141.el6.i686                                                              5/10

  Installing : 4:perl-5.10.1-141.el6.i686                                                                   6/10

  Installing : perl-DBI-1.609-4.el6.i686                                                                    7/10

  Installing : perl-DBD-MySQL-4.013-3.el6.i686                                                              8/10

  Installing : mysql-5.1.73-5.el6_6.i686                                                                    9/10

  Installing : mysql-server-5.1.73-5.el6_6.i686                                                            10/10

  Verifying  : mysql-5.1.73-5.el6_6.i686                                                                    1/10

  Verifying  : mysql-server-5.1.73-5.el6_6.i686                                                             2/10

  Verifying  : 4:perl-libs-5.10.1-141.el6.i686                                                              3/10

  Verifying  : perl-DBD-MySQL-4.013-3.el6.i686                                                              4/10

  Verifying  : 1:perl-Pod-Escapes-1.04-141.el6.i686                                                         5/10

  Verifying  : 1:perl-Pod-Simple-3.13-141.el6.i686                                                          6/10

  Verifying  : perl-DBI-1.609-4.el6.i686                                                                    7/10

  Verifying  : 1:perl-Module-Pluggable-3.90-141.el6.i686                                                    8/10

  Verifying  : 3:perl-version-0.77-141.el6.i686                                                             9/10

  Verifying  : 4:perl-5.10.1-141.el6.i686                                                                  10/10

 

Installed:

  mysql-server.i686 0:5.1.73-5.el6_6                                                                            

 

Dependency Installed:

  mysql.i686 0:5.1.73-5.el6_6                               perl.i686 4:5.10.1-141.el6                         

  perl-DBD-MySQL.i686 0:4.013-3.el6                         perl-DBI.i686 0:1.609-4.el6                        

  perl-Module-Pluggable.i686 1:3.90-141.el6                 perl-Pod-Escapes.i686 1:1.04-141.el6               

  perl-Pod-Simple.i686 1:3.13-141.el6                       perl-libs.i686 4:5.10.1-141.el6                    

  perl-version.i686 3:0.77-141.el6                        

 

Complete!

root@cent42:/var/www/html>

 

 2)啓動服務器

root@cent42:/root> service mysqld start

Initializing MySQL database:  WARNING: The host 'cent42' could not be looked up with resolveip.

This probably means that your libc libraries are not 100 % compatible

with this binary MySQL version. The MySQL daemon, mysqld, should work

normally with the exception that host name resolving will not work.

This means that you should use IP addresses instead of hostnames

when specifying MySQL privileges !

Installing MySQL system tables...

OK

Filling help tables...

OK

 

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

 

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

 

/usr/bin/mysqladmin -u root password 'new-password'

/usr/bin/mysqladmin -u root -h cent42 password 'new-password'

 

Alternatively you can run:

/usr/bin/mysql_secure_installation

 

which will also give you the option of removing the test

databases and anonymous user created by default.  This is

strongly recommended for production servers.

 

See the manual for more instructions.

 

You can start the MySQL daemon with:

cd /usr ; /usr/bin/mysqld_safe &

 

You can test the MySQL daemon with mysql-test-run.pl

cd /usr/mysql-test ; perl mysql-test-run.pl

 

Please report any problems with the /usr/bin/mysqlbug script!

 

[  OK  ]

Starting mysqld:  [  OK  ]

3)放通防火牆

使用命令以下:

iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT (關於iptabls的詳細解釋請見iptables章節)

4) 執行安全性設置

包括設置root密碼、刪除測試數據庫等:這裏設置root密碼將是你登錄數據庫使用的密碼)

root@cent42:/root> /usr/bin/mysql_secure_installation

 

 

 

 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL

      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

 

 

In order to log into MySQL to secure it, we'll need the current

password for the root user.  If you've just installed MySQL, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

 

Enter current password for root (enter for none):

OK, successfully used password, moving on...

 

Setting the root password ensures that nobody can log into the MySQL

root user without the proper authorisation.

 

Set root password? [Y/n] Y

New password:

Re-enter new password:

Password updated successfully!

Reloading privilege tables..

 ... Success!

 

 

By default, a MySQL installation has an anonymous user, allowing anyone

to log into MySQL without having to have a user account created for

them.  This is intended only for testing, and to make the installation

go a bit smoother.  You should remove them before moving into a

production environment.

 

Remove anonymous users? [Y/n] Y

 ... Success!

 

Normally, root should only be allowed to connect from 'localhost'.  This

ensures that someone cannot guess at the root password from the network.

 

Disallow root login remotely? [Y/n] Y

 ... Success!

 

By default, MySQL comes with a database named 'test' that anyone can

access.  This is also intended only for testing, and should be removed

before moving into a production environment.

 

Remove test database and access to it? [Y/n] Y

 - Dropping test database...

 ... Success!

 - Removing privileges on test database...

 ... Success!

 

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

 

Reload privilege tables now? [Y/n] Y

 ... Success!

 

Cleaning up...

 

 

 

All done!  If you've completed all of the above steps, your MySQL

installation should now be secure.

 

Thanks for using MySQL!

 

 

root@cent42:/root>

 

 上述內容執行完成後,你的mysql就應該安裝好了,若是你想使用PHP MyAdmin的話,還須要安裝Apache以及PHP,因此,接下來,咱們繼續安裝着2部分的內容
 
2.安裝Apache(httpd)
2.1 經過yum進行安裝
Command :yum install httpd
2.2 啓動httpd 服務
chkconfig httpd on
這裏須要注意,須要確認httpd的3個5處於on的狀態,輸入chkconfig以後,找到httpd,進行check便可。
2.3 啓動http
service httpd start
2.4 配置防火牆

在「/etc/sysconfig/iptables」文件中「-A INPUT ... --dport 22 -j ACCEPT」一行後面添加放通80端口的規則。具體命令以下:

"-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT"

重啓防火牆(service iptables restart)

上述操做完成後,你能夠經過瀏覽器去訪問以下的地址(地址就是你搭建虛擬機的地址)

http://135.251.124.24/

會出現一個Apache的界面

如今,你只要在服務器的「/var/www/html/」這個目錄中添加相關的html文件,就能夠訪問了。

 

3.安裝PHP

yum install php php-mysql

這裏僅僅安裝了PHP軟件自己,和用於php-mysql鏈接的庫,實際在訪問PHP的時候,還須要裝其餘的插件,因此,如何找打和PHP相關的插件呢?可使用以下命令:

yum search php-,這裏命令能夠列出全部的PHP的安裝包,若是你想知道每一個模塊是幹什麼的,可使用「yum info php-common」這樣的命令去查看

安裝完成後,須要重啓Apache HTTP Server :

service httpd restart

測試下PHP是否安裝成功,可否解析PHP代碼。進入以下目錄:

cd /var/www/html/

編輯以下文件:

root@cent42:/var/www/html> vi info.php

添加以下信息:

<?php

phpinfo();

?>

保存退出後,瀏覽器中輸入:

 

http://135.251.124.24//info.php,應該就能夠看到PHP的網頁了。

 

安裝phpMyAdmin

找到一個phpMyAdmin的包,將其放在你的服務器上,我是直接放在了/var/www/html下,而後解壓,將名稱更改成phpMyAdmin便可。這樣,你就能夠經過訪問http://135.252.4.25/phpMyAdmin/來訪問phpMyAdmin,從而來訪問管理你的數據庫了。

用戶名就是root,密碼就是你在上面設置的密碼。

 

4.如何導入導出數據庫

若是你有一個源數據庫,你想將它導入到你搭建的服務器上,那麼應該如何實現呢,能夠用以下的命令:

先經過以下命令到源數據庫中將數據導出:

mysqldump --password=xxx(密碼) --user=root(用戶) --add-drop-table --databases xxx(源DB的名字) --result-file=/home/xxx.sql(目標)

 

 

而後登錄到目標數據庫(我這裏就是登錄到24上),建立一個新的database:

mysqladmin --user=root --password=xxx create mh_db_bak_20160811

 

而後將剛纔導出的文件上傳到目標數據庫的同一個服務器上(經過FTP等先將導出的數據庫傳入到你的目標服務器上),執行下面的命令導入文件:

mysql --user=root --password=xxx mh_db_bak_20160811 < cif4db.sql

 

這樣,你打開你的PHPMyAdmin的時候,就能夠看到導入的數據庫了,能夠執行你的查詢等操做啦。

相關文章
相關標籤/搜索