1、准备一台vmware虚拟机centos7服务器,作为apache(httpd),mariadb,php服务器:配置ip地址为192.168.10.20;这里php作为httpd的模块来实现动态资源加载。
安装lamp:
程序包:httpd,php,php-mysql,mariadb-server:
# yum -y install httpd php php-mysql mariadb-server
# systemctl start httpd.service
# systemctl start mariadb.service
# vim /var/www/html/phpinfo.php
....php code....
?>
# systemctl restart httpd
使用浏览器打开192.168.10.20/phpinfo.php,能打开成功表示php资源加载成功:
连接至mariadb:
# mysql
创建新的数据库名为mydb
MariaDB [(none)]> CREATE DATABASE mydb;
查看所有当前已有数据库
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| luhao |
| mydb |
| mysql |
| performance_schema |
| test |
+--------------------+
6 rows in set (0.00 sec)
切换默认数据库为mydb
MariaDB [(none)]> USE mydb;
Database changed
查看当前库mydb中的表
MariaDB [mydb]> SHOW TABLES;
Empty set (0.00 sec)
创建新表tabl1,一个字段id 数值型
MariaDB [mydb]> CREATE TABLE tabl1 (id INT);
Query OK, 0 rows affected (0.04 sec)
查看当前数据库的表
MariaDB [mydb]> SHOW TABLES;
+----------------+
| Tables_in_mydb |
+----------------+
| tabl1 |
+----------------+
1 row in set (0.00 sec)
切换到元数据数据库mysql
MariaDB [mydb]> USE mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
查看当前库中的表
MariaDB [mysql]> SHOW TABLES;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
24 rows in set (0.00 sec)
展示mysql库中的user表字段信息
MariaDB [mysql]> DESC user;
+------------------------+-----------------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+---------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(16) | NO | PRI | | |
| Password | char(41) | NO | | | |
| Select_priv | enum('N','Y') | NO | | N | |
| Insert_priv | enum('N','Y') | NO | | N | |
| Update_priv | enum('N','Y') | NO | | N | |
| Delete_priv | enum('N','Y') | NO | | N | |
| Create_priv | enum('N','Y') | NO | | N | |
| Drop_priv | enum('N','Y') | NO | | N | |
| Reload_priv | enum('N','Y') | NO | | N | |
| Shutdown_priv | enum('N','Y') | NO | | N | |
| Process_priv | enum('N','Y') | NO | | N | |
| File_priv | enum('N','Y') | NO | | N | |
| Grant_priv | enum('N','Y') | NO | | N | |
| References_priv | enum('N','Y') | NO | | N | |
| Index_priv | enum('N','Y') | NO | | N | |
| Alter_priv | enum('N','Y') | NO | | N | |
| Show_db_priv | enum('N','Y') | NO | | N | |
| Super_priv | enum('N','Y') | NO | | N | |
| Create_tmp_table_priv | enum('N','Y') | NO | | N | |
| Lock_tables_priv | enum('N','Y') | NO | | N | |
| Execute_priv | enum('N','Y') | NO | | N | |
| Repl_slave_priv | enum('N','Y') | NO | | N | |
| Repl_client_priv | enum('N','Y') | NO | | N | |
| Create_view_priv | enum('N','Y') | NO | | N | |
| Show_view_priv | enum('N','Y') | NO | | N | |
| Create_routine_priv | enum('N','Y') | NO | | N | |
| Alter_routine_priv | enum('N','Y') | NO | | N | |
| Create_user_priv | enum('N','Y') | NO | | N | |
| Event_priv | enum('N','Y') | NO | | N | |
| Trigger_priv | enum('N','Y') | NO | | N | |
| Create_tablespace_priv | enum('N','Y') | NO | | N | |
| ssl_type | enum('','ANY','X509','SPECIFIED') | NO | | | |
| ssl_cipher | blob | NO | | NULL | |
| x509_issuer | blob | NO | | NULL | |
| x509_subject | blob | NO | | NULL | |
| max_questions | int(11) unsigned | NO | | 0 | |
| max_updates | int(11) unsigned | NO | | 0 | |
| max_connections | int(11) unsigned | NO | | 0 | |
| max_user_connections | int(11) | NO | | 0 | |
| plugin | char(64) | NO | | | |
| authentication_string | text | NO | | NULL | |
+------------------------+-----------------------------------+------+-----+---------+-------+
42 rows in set (0.00 sec)
查看user表中的字段Host,User,Password信息
ariaDB [mysql]> SELECT Host,User,Password FROM user;
+---------------+------+-------------------------------------------+
| Host | User | Password |
+---------------+------+-------------------------------------------+
| localhost | root | *C0353E4C03698F45A04E1B3B9412544B3D16AD59 |
| centos7-node2 | root | |
| 127.0.0.1 | root | |
| ::1 | root | |
| localhost | | |
| centos7-node2 | | |
+---------------+------+-------------------------------------------+
6 rows in set (0.01 sec)
查询结果中的多个root用户对应多个Host并不是同一个用户,修改root用户对应主机名为localhost的密码为lhp@ssw0rd
MariaDB [mysql]> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('lhp@ssw0rd');
Query OK, 0 rows affected (0.02 sec)
使用宿主机下载phpmyadmin图形工具用于图形化管理数据库:由于当前php版本为5.4.16,所以从https://www.phpmyadmin.net/files/找到降低版本phpMyAdmin-4.0.10.20-all-languages.zip,上传至centos7服务器/root目录下。
切换到/root目录下
# cd /root
解压phpMyAdmin-4.0.10.20-all-languages.zip
# unzip phpMyAdmin-4.0.10.20-all-languages.zip
将phpMyAdmin-4.0.10.20-all-languages移动到httpd的默认网页目录下/var/www/并创建/var/www/pma目录:
# mv phpMyAdmin-4.0.10.20-all-languages /var/www/pma
尝试访问192.168.10.20/pma
提示缺少mbstring,在centos7中安装该模块:
# yum -y install php-mbstring
安装之后相当于php环境改变了,需要重启httpd
# systemctl restart httpd