如何安装使用PHP MyAdmin
前言:
? 因為工作的原因,很多地方需要用到數據庫查詢,為了避免破壞真實存在的數據庫,所以,我搭建了一個虛擬機,在搭建的虛擬機上將數據庫進行了導入。這里,用了一個PHP myAdmin的工具,個人覺得還是非常方便控制管理數據庫的。故做了下研究,寫下此文章記錄下。
?
PHP myAdmin簡介
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-server
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 installed
--> 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的時候,就可以看到導入的數據庫了,可以執行你的查詢等操作啦。
?
?
?
轉載于:https://www.cnblogs.com/syplovertest/p/6094639.html
總結
以上是生活随笔為你收集整理的如何安装使用PHP MyAdmin的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用python对redis备份zset
- 下一篇: php定时删除文件夹下文件(清理缓存文件