如何安装使用PHP MyAdmin
前言:
? 因?yàn)楣ぷ鞯脑?#xff0c;很多地方需要用到數(shù)據(jù)庫查詢,為了避免破壞真實(shí)存在的數(shù)據(jù)庫,所以,我搭建了一個(gè)虛擬機(jī),在搭建的虛擬機(jī)上將數(shù)據(jù)庫進(jìn)行了導(dǎo)入。這里,用了一個(gè)PHP myAdmin的工具,個(gè)人覺得還是非常方便控制管理數(shù)據(jù)庫的。故做了下研究,寫下此文章記錄下。
?
PHP myAdmin簡介
phpMyAdmin 是一個(gè)以PHP為基礎(chǔ),以Web-Base方式架構(gòu)在網(wǎng)站主機(jī)上的MySQL的數(shù)據(jù)庫管理工具,讓管理者可用Web接口管理MySQL數(shù)據(jù)庫。借由此Web接口可以成為一個(gè)簡易方式輸入繁雜SQL語法的較佳途徑,尤其要處理大量資料的匯入及匯出更為方便。其中一個(gè)更大的優(yōu)勢在于由于phpMyAdmin跟其他PHP程式一樣在網(wǎng)頁服務(wù)器上執(zhí)行,但是您可以在任何地方使用這些程式產(chǎn)生的HTML頁面,也就是于遠(yuǎn)端管理MySQL數(shù)據(jù)庫,方便的建立、修改、刪除數(shù)據(jù)庫及資料表。也可借由phpMyAdmin建立常用的php語法,方便編寫網(wǎng)頁時(shí)所需要的sql語法正確性。 具體安裝步驟: 1.安裝mysql 如果你的服務(wù)器上安裝配置好了yum源的話,一切都變了簡單了,具體操作執(zhí)行命令如下: 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)啟動服務(wù)器
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 (關(guān)于iptabls的詳細(xì)解釋請見iptables章節(jié))
4) 執(zhí)行安全性設(shè)置
包括設(shè)置root密碼、刪除測試數(shù)據(jù)庫等:這里設(shè)置root密碼將是你登陸數(shù)據(jù)庫使用的密碼)
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>
?
上述內(nèi)容執(zhí)行完成后,你的mysql就應(yīng)該安裝好了,如果你想使用PHP MyAdmin的話,還需要安裝Apache以及PHP,所以,接下來,我們繼續(xù)安裝著2部分的內(nèi)容 2.安裝Apache(httpd) 2.1 通過yum進(jìn)行安裝 Command :yum install httpd 2.2 啟動httpd 服務(wù) chkconfig httpd on 這里需要注意,需要確認(rèn)httpd的3個(gè)5處于on的狀態(tài),輸入chkconfig之后,找到httpd,進(jìn)行check即可。 2.3 啟動http service httpd start 2.4 配置防火墻在“/etc/sysconfig/iptables”文件中“-A INPUT ... --dport 22 -j ACCEPT”一行后面添加放通80端口的規(guī)則。具體命令如下:
"-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT"
重啟防火墻(service iptables restart)
上述操作完成后,你可以通過瀏覽器去訪問如下的地址(地址就是你搭建虛擬機(jī)的地址)
http://135.251.124.24/
會出現(xiàn)一個(gè)Apache的界面
現(xiàn)在,你只要在服務(wù)器的“/var/www/html/”這個(gè)目錄中添加相關(guān)的html文件,就可以訪問了。
?
3.安裝PHP
yum install php php-mysql
這里僅僅安裝了PHP軟件本身,和用于php-mysql連接的庫,實(shí)際在訪問PHP的時(shí)候,還需要裝其他的插件,所以,如何找打和PHP相關(guān)的插件呢?可以使用如下命令:
yum search php-,這里命令可以列出所有的PHP的安裝包,如果你想知道每個(gè)模塊是干什么的,可以使用“yum info php-common”這樣的命令去查看
安裝完成后,需要重啟Apache HTTP Server :
service httpd restart
測試下PHP是否安裝成功,能否解析PHP代碼。進(jìn)入如下目錄:
cd /var/www/html/
編輯如下文件:
root@cent42:/var/www/html> vi info.php
添加如下信息:
<?php
phpinfo();
?>
保存退出后,瀏覽器中輸入:
?
http://135.251.124.24//info.php,應(yīng)該就可以看到PHP的網(wǎng)頁了。
?
安裝phpMyAdmin
找到一個(gè)phpMyAdmin的包,將其放在你的服務(wù)器上,我是直接放在了/var/www/html下,然后解壓,將名稱更改為phpMyAdmin即可。這樣,你就可以通過訪問http://135.252.4.25/phpMyAdmin/來訪問phpMyAdmin,從而來訪問管理你的數(shù)據(jù)庫了。
用戶名就是root,密碼就是你在上面設(shè)置的密碼。
?
4.如何導(dǎo)入導(dǎo)出數(shù)據(jù)庫
如果你有一個(gè)源數(shù)據(jù)庫,你想將它導(dǎo)入到你搭建的服務(wù)器上,那么應(yīng)該如何實(shí)現(xiàn)呢,可以用如下的命令:
先通過如下命令到源數(shù)據(jù)庫中將數(shù)據(jù)導(dǎo)出:
mysqldump --password=xxx(密碼) --user=root(用戶) --add-drop-table --databases xxx(源DB的名字) --result-file=/home/xxx.sql(目標(biāo))
?
?
然后登陸到目標(biāo)數(shù)據(jù)庫(我這里就是登陸到24上),創(chuàng)建一個(gè)新的database:
mysqladmin --user=root --password=xxx create mh_db_bak_20160811
?
然后將剛才導(dǎo)出的文件上傳到目標(biāo)數(shù)據(jù)庫的同一個(gè)服務(wù)器上(通過FTP等先將導(dǎo)出的數(shù)據(jù)庫傳入到你的目標(biāo)服務(wù)器上),執(zhí)行下面的命令導(dǎo)入文件:
mysql --user=root --password=xxx mh_db_bak_20160811 < cif4db.sql
?
這樣,你打開你的PHPMyAdmin的時(shí)候,就可以看到導(dǎo)入的數(shù)據(jù)庫了,可以執(zhí)行你的查詢等操作啦。
?
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/syplovertest/p/6094639.html
總結(jié)
以上是生活随笔為你收集整理的如何安装使用PHP MyAdmin的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用python对redis备份zset
- 下一篇: java 高效批量插入 sqlserve