linux下用网页管理数据库

一、安装php服务

[root@foundation66 ~]#  yum install php -y 
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
              : manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package php.x86_64 0:5.4.16-36.el7_1 will be installed
--> Processing Dependency: php-common(x86-64) = 5.4.16-36.el7_1 for package: php-5.4.16-36.el7_1.x86_64
--> Processing Dependency: php-cli(x86-64) = 5.4.16-36.el7_1 for package: php-5.4.16-36.el7_1.x86_64
--> Running transaction check
---> Package php-cli.x86_64 0:5.4.16-36.el7_1 will be installed
---> Package php-common.x86_64 0:5.4.16-36.el7_1 will be installed
--> Processing Dependency: libzip.so.2()(64bit) for package: php-common-5.4.16-36.el7_1.x86_64
--> Running transaction check
---> Package libzip.x86_64 0:0.10.1-8.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package           Arch          Version                   Repository      Size
================================================================================
Installing:
 php               x86_64        5.4.16-36.el7_1           rhel7.2        1.4 M
Installing for dependencies:
 libzip            x86_64        0.10.1-8.el7              rhel7.2         49 k
 php-cli           x86_64        5.4.16-36.el7_1           rhel7.2        2.7 M
 php-common        x86_64        5.4.16-36.el7_1           rhel7.2        563 k

Transaction Summary
================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 4.7 M
Installed size: 17 M
Downloading packages:
--------------------------------------------------------------------------------
Total                                               46 MB/s | 4.7 MB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libzip-0.10.1-8.el7.x86_64                                   1/4 
  Installing : php-common-5.4.16-36.el7_1.x86_64                            2/4 
  Installing : php-cli-5.4.16-36.el7_1.x86_64                               3/4 
  Installing : php-5.4.16-36.el7_1.x86_64                                   4/4 
  Verifying  : php-5.4.16-36.el7_1.x86_64                                   1/4 
  Verifying  : php-cli-5.4.16-36.el7_1.x86_64                               2/4 
  Verifying  : libzip-0.10.1-8.el7.x86_64                                   3/4 
  Verifying  : php-common-5.4.16-36.el7_1.x86_64                            4/4 

Installed:
  php.x86_64 0:5.4.16-36.el7_1                                                  

Dependency Installed:
  libzip.x86_64 0:0.10.1-8.el7             php-cli.x86_64 0:5.4.16-36.el7_1     
  php-common.x86_64 0:5.4.16-36.el7_1     

Complete!
[root@foundation66 ~]# cd /var/www/html/
[root@foundation66 html]# ls
rhel7.0  phpMyAdmin-3.4.0-all-languages.tar.bz2 
[root@foundation66 html]# tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2 ##解压安装包
[root@foundation66 html]# mv phpMyAdmin-3.4.0-all-languages/ mysqladmin  ##重命名

安装php所需组件
[root@foundation66 html]# systemctl restart httpd   ##重启服务

打开浏览器
http://172.25.254.66/myadmin



 

二、数据库中的用户管理

1.创建用户

[root@foundation66 html]# systemctl start mariadb
[root@foundation66 html]# mysql -uroot -predhat
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.44-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create user student@localhost identified by 'redhat'   ##student@'%'代表远程用户
    -> ;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> select user from mysql.user
    -> ;
+---------+
| user    |
+---------+
| root    |
| root    |
| root    |
| student |
+---------+
4 rows in set (0.00 sec)

2、用户的授权与查看

MariaDB [(none)]> grant insert,update,delete,select on westos.* to student@localhost;  ##给予用户上传,删除,写入,查看的权力
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show grants for student@localhost; 检查是否添加成功
+----------------------------------------------------------------------------------------------------------------+
| Grants for student@localhost                                                                                   |
+----------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'student'@'localhost' IDENTIFIED BY PASSWORD '*84BB5DF4823DA319BBF86C99624479A198E6EEE9' |
| GRANT SELECT, INSERT, UPDATE, DELETE ON `westos`.* TO 'student'@'localhost'                                    |
+----------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

MariaDB [(none)]> revoke update on westos.* from student@localhost;  去掉上传的能力
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> show grants for student@localhost;  ##检查
+----------------------------------------------------------------------------------------------------------------+
| Grants for student@localhost                                                                                   |
+----------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'student'@'localhost' IDENTIFIED BY PASSWORD '*84BB5DF4823DA319BBF86C99624479A198E6EEE9' |
| GRANT SELECT, INSERT, DELETE ON `westos`.* TO 'student'@'localhost'                                            |
+----------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

MariaDB [(none)]> drop user student@localhost;  ##删除用户
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> select user from mysql.user;
+------+
| user |
+------+
| root |
| root |
| root |
+------+
3 rows in set (0.00 sec)

3、用命令行管理数据库

[root@foundation66 html]# mysql -uroot -predhat -e "show databases"; ##-e可直接执行命令
+--------------------+
| Database           |
+--------------------+
| information_schema |
| linux              |
| mysql              |
| performance_schema |
+--------------------+

[root@foundation66 html]# mysqladmin -uroot -predhat password 'linux' 更改用户密码


三、备份数据库

[root@foundation66 html]# mysql -uroot -predhat -e "show databases";
+--------------------+
| Database           |
+--------------------+
| information_schema |
| linux              |
| mysql              |
| performance_schema |
+--------------------+
[root@foundation66 html]# mysqldump -uroot -predhat westos > /mnt/westos.sql   ##备份到mnt下
mysqldump: Got error: 1049: "Unknown database 'westos'" when selecting the database
[root@foundation66 html]# mysqldump -uroot -predhat linux > /mnt/westos.sql
[root@foundation66 html]# mysql -uroot -predhat -e'drop database linux'
[root@foundation66 html]# mysql -uroot -predhat -e'show databases'  
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
[root@foundation66 html]# mysql -uroot -predhat linux < /mnt/westos.sql  恢复备份
ERROR 1049 (42000): Unknown database 'linux'  缺少数据库 只需建立一个就可以再次导入
[root@foundation66 html]# vim /mnt/westos.sql 


之后导入文件

第二种就是手动在mysql中建立linux数据库 导入数据



猜你喜欢

转载自blog.csdn.net/a313434458/article/details/80518254