设为首页 收藏本站
查看: 903|回复: 0

[经验分享] Linux应用:php、mysql基础

[复制链接]

尚未签到

发表于 2018-10-11 08:11:14 | 显示全部楼层 |阅读模式
  php、mysql基础
  一、安装PHP
  [root@test tmp]# rpm -ql php53
  package php53 is not installed
  [root@test tmp]# rpm -ivh php53-common-5.3.3-23.el5_10.i386.rpm

  warning: php53-common-5.3.3-23.el5_10.i386.rpm: Header V3 DSA signature: NOKEY, key>  Preparing...       ###################### [100%]
  1:php53-common   #################### [100%]
  [root@test tmp]# rpm -ivh php53-cli-5.3.3-23.el5_10.i386.rpm

  warning: php53-cli-5.3.3-23.el5_10.i386.rpm: Header V3 DSA signature: NOKEY, key>  Preparing...        ##################### [100%]
  1:php53-cli      ####################### [100%]
  [root@test tmp]# rpm -ivh php53-mbstring-5.3.3-23.el5_10.i386.rpm

  warning: php53-mbstring-5.3.3-23.el5_10.i386.rpm: Header V3 DSA signature: NOKEY, key>  Preparing...     ################### [100%]
  1:php53-mbstring   ################# [100%]
  [root@test tmp]# rpm -ivh php53-5.3.3-23.el5_10.i386.rpm

  warning: php53-5.3.3-23.el5_10.i386.rpm: Header V3 DSA signature: NOKEY, key>  Preparing...    ############# [100%]
  1:php53      ############## [100%]
  [root@test tmp]# rpm -ql php53
  /etc/httpd/conf.d/php.conf          #PHP配制文件
  /usr/lib/httpd/modules/libphp5.so   #PHP模块
  /var/lib/php/session             #PHP会话文件
  /var/www/icons/php.gif
  [root@test conf.d]# service httpd restart
  Stopping httpd:                        [  OK  ]
  Starting httpd:                         [  OK  ]
  [root@test conf.d]# cd /www/a.org/
  [root@test a.org]# ls
  index.html
  [root@test a.org]# mv index.html index.php
  [root@test a.org]# vi index.php
  A
  a.org
  
DSC0000.png

  二、安装mysql
  [root@test a.org]# yum -y install mysql-server
  ...
  Installing     : perl-DBI                          1/4
  Installing     : mysql                              2/4
  Installing     : perl-DBD-MySQL           3/4
  Installing     : mysql-server                  4/4
  ...
  Complete!
  [root@test a.org]# service mysqld start
  Initializing MySQL database:  Installing MySQL system tables...
  161229 16:01:45 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
  161229 16:01:45 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
  OK
  Filling help tables...
  161229 16:01:45 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
  161229 16:01:45 [Warning] option 'max_join_size': unsigned value 18446744073709551615 adjusted to 4294967295
  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 jacktest 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 mysql-test ; perl mysql-test-run.pl
  Please report any problems with the /usr/bin/mysqlbug script!
  The latest information about MySQL is available on the web at
  http://www.mysql.com
  Support MySQL by buying support/licenses at http://shop.mysql.com
  [  OK  ]
  Starting MySQL:          [  OK  ]
  [root@jacktest yum.repos.d]# mysql
  Welcome to the MySQL monitor.  Commands end with ; or \g.

  Your MySQL connection>  Server version: 5.0.77 Source distribution
  Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
  mysql> SHOW DATABASES;
  +--------------------+
  | Database   |
  +--------------------+
  | information_schema |
  | mysql      |
  | test      |
  +--------------------+
  3 rows in set (0.01 sec)
  mysql> CREATE DATABASE IF NOT EXISTS testdb;
  Query OK, 1 row affected (0.01 sec)     #创建数据库
  mysql> SHOW DATABASES;
  +--------------------+
  | Database    |
  +--------------------+
  | information_schema |
  | mysql       |
  | test        |
  | testdb     |
  +--------------------+
  4 rows in set (0.00 sec)
  mysql> DROP DATABASE IF EXISTS testdb;  #删除表后无法恢复
  Query OK, 0 rows affected (0.00 sec)
  mysql> USE mydb;
  Database changed
  mysql> CREATE TABLE students(Name CHAR(10) NOT NULL,Age TINYINT UNSIGNED, Gender CHAR(1) NOT NULL);   #创建表
  Query OK, 0 rows affected (0.00 sec)
  mysql> SHOW TABLES;
  +----------------+
  | Tables_in_mydb |
  +----------------+
  | students       |
  +----------------+
  1 row in set (0.00 sec)
  mysql> DESC students;  #查看表结构
  +--------+---------------------+------+-----+---------+-------+
  | Field  | Type    | Null | Key | Default | Extra |
  +--------+---------------------+------+-----+---------+-------+
  | Name   | char(10)  | NO   |     | NULL  |       |
  | Age    | tinyint(3) unsigned | YES  |     | NULL  |      |
  | Gender | char(1)  | NO   |     | NULL |       |
  +--------+---------------------+------+-----+---------+-------+
  3 rows in set (0.00 sec)

  mysql>>  Query OK, 0 rows affected (0.01 sec)  #新增表字段
  Records: 0  Duplicates: 0  Warnings: 0
  mysql> DESC students;
  +--------+---------------------+------+-----+---------+-------+
  | Field  | Type   | Null | Key | Default | Extra |
  +--------+---------------------+------+-----+---------+-------+
  | Name   | char(10)   | NO   |     | NULL    |       |
  | Age    | tinyint(3) unsigned | YES  |     | NULL    |       |
  | Gender | char(1)  | NO   |     | NULL    |       |
  | course | varchar(100)   | YES  |     | NULL    |       |
  +--------+---------------------+------+-----+---------+-------+
  4 rows in set (0.00 sec)
  mysql> INSERT INTO students (Name,Gender) VALUE ('LHH','M'),('LCC','F') ;
  Query OK, 2 rows affected (0.00 sec)    #新增表字段值1
  Records: 2  Duplicates: 0  Warnings: 0
  mysql> SELECT * FROM students;
  +------+------+--------+--------+
  | Name | Age  | Gender | course |
  +------+------+--------+--------+
  | LHH  | NULL | M    | NULL   |
  | LCC  | NULL | F    | NULL   |
  +------+------+--------+--------+
  2 rows in set (0.00 sec)
  mysql> INSERT INTO students VALUES ('WFX',33,'M','XXX');
  Query OK, 1 row affected, 1 warning (0.00 sec)  #新增表字段值2
  mysql> SELECT * FROM students;
  +------+------+--------+--------+
  | Name | Age  | Gender | course |
  +------+------+--------+--------+
  | LHH  | NULL | M  | NULL   |
  | LCC  | NULL | F  | NULL   |
  | WWW | 33 |   M  |  XXX   |
  +------+------+--------+--------+
  3 rows in set (0.01 sec)
  mysql> UPDATE students SET Course='Tec';
  Query OK, 4 rows affected (0.01 sec)   #更新表中所有Course值
  Rows matched: 4  Changed: 4  Warnings: 0
  mysql> select * from students;
  +------+--------+------+--------+
  | Name | Course | Age  | Gender |
  +------+--------+------+--------+
  | LHH  | Tec    | NULL | M      |
  | LCC  | Tec    | NULL | F      |
  | WFX  | Tec    |   22 | M      |
  | WWW  | Tec    |   33 | M      |
  +------+--------+------+--------+
  4 rows in set (0.00 sec)
  mysql> DELETE FROM students WHERE Gender='M';
  Query OK, 3 rows affected (0.00 sec)   #删除表中所有男性
  mysql> select * from students;
  +------+--------+------+--------+
  | Name | Course | Age  | Gender |
  +------+--------+------+--------+
  | LCC  | Tec    | NULL | F      |
  +------+--------+------+--------+
  1 row in set (0.00 sec)
  三、创建mysql用户

  mysql> CREATE USER 'jerry'@'%'>  Query OK, 0 rows affected (0.01 sec)
  mysql> SHOW GRANTS FOR 'jerry'@'%';   #查看用户授权
  +-----------------------------------------------------------------------------+
  | Grants for jerry@%        |
  +-----------------------------------------------------------------------------+

  | GRANT USAGE ON *.* TO 'jerry'@'%'>  +-----------------------------------------------------------------------------+
  1 row in set (0.00 sec)
  mysql> GRANT ALL PRIVILEGES ON mydb.* TO 'jerry'@'%';
  Query OK, 0 rows affected (0.00 sec)
  mysql> SHOW GRANTS FOR  'jerry'@'%';
  +-----------------------------------------------------------------------------+
  | Grants for jerry@%       |
  +-----------------------------------------------------------------------------+

  | GRANT USAGE ON *.* TO 'jerry'@'%'>  | GRANT ALL PRIVILEGES ON `mydb`.* TO 'jerry'@'%'     |
  +-----------------------------------------------------------------------------+
  2 rows in set (0.00 sec)
  [root@jacktest yum.repos.d]# mysql -ujerry -p -h10.109.131.209  #换一台主机远程登录
  四、无密码登录、改密码
  [root@jacktest ~]# mysql
  ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)
  [root@jacktest ~]# mysql -uroot -p
  Enter password:
  ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)
  解决方案
  [root@jacktest ~]# service mysqld stop   #1 中止mysqld服务
  [root@jacktest ~]# mysqld_safe --skip-grant-tables &    #2 安全模式启动mysqld服务
  [1] 9671
  [root@jacktest ~]# Starting mysqld daemon with databases from /var/lib/mysql
  启动mysqld_safe ,跳过启动授权表。启动时加上skip-grant-tables参数目的是在启动mysql时不启动grant-tables,授权表。这样就可以修改root的密码了
  [root@jacktest ~]# mysql -uroot -p    #3 进入mysql
  Enter password:     #4 要求输入密码时,直接回车即可。
  Welcome to the MySQL monitor.  Commands end with ; or \g.

  Your MySQL connection>  Server version: 5.0.77 Source distribution
  Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
  mysql> use mysql;    #5 修改密码
  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
  mysql> update user set password=PASSWORD('123456') where user="root" and host=127.0.0.1;
  Query OK, 3 rows affected (0.01 sec)
  Rows matched: 3  Changed: 3  Warnings: 0
  mysql> flush privileges;
  Query OK, 0 rows affected (0.00 sec)
  mysql> quit
  [root@jacktest ~]# ps -au mysql     #6 查看mysql进程且清除
  PID TTY          TIME CMD
  9585 pts/1    00:00:00 mysqld_safe
  9618 pts/1    00:00:00 mysqld
  9658 pts/0    00:00:00 ps
  [root@jacktest ~]# kill -9 9585
  [root@jacktest ~]# ps -au mysql
  PID TTY          TIME CMD
  9618 pts/1    00:00:00 mysqld
  9659 pts/0    00:00:00 ps
  [root@jacktest ~]# kill -9 9618
  五、基础练习
  mysql> CREATE DATABASES testdb ;
  Query OK, 1 row affected (0.01 sec)
  mysql> show databases;
  +--------------------+
  | Database    |
  +--------------------+
  | information_schema |
  | mydb      |
  | mysql     |
  | test        |
  | testdb    |
  +--------------------+
  5 rows in set (0.00 sec)
  mysql> CREATE TABLE students(ID TINYINT(6) NOT NULL,Name CHAR(10) NOT NULL,Age TINYINT(3) UNSIGNED,Gender CHAR(1) NOT NULL,Course VARCHAR(100));
  Query OK, 0 rows affected (0.01 sec)
  mysql> DESC students;
  +--------+---------------------+------+-----+---------+-------+
  | Field  | Type   | Null | Key | Default | Extra |
  +--------+---------------------+------+-----+---------+-------+

  |>  | Name  | char(10)   | NO   |     | NULL    |       |
  | Age  | tinyint(3) unsigned | YES  |     | NULL    |       |
  | Gender | char(1)    | NO   |     | NULL    |       |
  | Course | varchar(100)  | YES  |     | NULL    |       |
  +--------+---------------------+------+-----+---------+-------+
  5 rows in set (0.00 sec)
  mysql> INSERT INTO students VALUES ('1','LiHZ',54,'M','Hamagong');
  mysql> INSERT INTO students VALUES ('2','Huangrong',24,'F','Dagou Bangfa');
  mysql> INSERT INTO students VALUES ('3','LuWS',16,'F','Jiuyang Shenggong');
  mysql> INSERT INTO students VALUES ('4','ZhuZL',56,'M','Pixie Jianfa');
  mysql> INSERT INTO students VALUES ('5','WFX',26,'M','XiangLong 18Zhang');
  mysql> SELECT * FROM students;
  +----+-----------+------+--------+-------------------+

  |>  +----+-----------+------+--------+-------------------+
  |  1 | LiHZ    |   54 | M      | Hamagong   |
  |  2 | Huangrong |   24 | F   | Dagou Bangfa |
  |  3 | LuWS   |   16 | F      | Jiuyang Shenggong |
  |  4 | ZhuZL  |   56 | M      | Pixie Jianfa   |
  |  5 | WFX    |   26 | M      | XiangLong 18Zhang |
  +----+-----------+------+--------+-------------------+
  5 rows in set (0.00 sec)
  5.1. 找出性别为女性的所有人;
  mysql> SELECT * FROM testdb.students WHERE Gender='F';
  +----+-----------+------+--------+-------------------+

  |>  +----+-----------+------+--------+-------------------+
  |  2 | Huangrong |   24 | F      | Dagou Bangfa |
  |  3 | LuWS      |   16 | F      | Jiuyang Shenggong |
  +----+-----------+------+--------+-------------------+
  2 rows in set (0.00 sec)
  5.2. 找出年龄大于30的所有人;
  mysql> SELECT * FROM testdb.students WHERE Age>30;
  +----+-------+------+--------+--------------+

  |>  +----+-------+------+--------+--------------+
  |  1 | LiHZ  |   54 | M      | Hamagong     |
  |  4 | ZhuZL |   56 | M      | Pixie Jianfa |
  +----+-------+------+--------+--------------+
  2 rows in set (0.00 sec)
  5.3. 修改LiHZ的课程为小李飞刀
  mysql> UPDATE  testdb.students SET Course='Xiaoli Feidao' WHERE Name='LiHZ';
  Query OK, 1 row affected (0.00 sec)
  Rows matched: 1  Changed: 1  Warnings: 0
  mysql> SELECT * FROM testdb.students WHERE Name='LiHZ';
  +----+------+------+--------+---------------+

  |>  +----+------+------+--------+---------------+
  |  1 | LiHZ |   54 | M      | Xiaoli Feidao |
  +----+------+------+--------+---------------+
  1 row in set (0.00 sec)
  5.4. 删除年龄小于30的所有人
  mysql> DELETE  FROM testdb.students WHERE Age SELECT * FROM testdb.students ;
  +----+-------+------+--------+---------------+

  |>  +----+-------+------+--------+---------------+
  |  1 | LiHZ  |   54 | M      | Xiaoli Feidao |
  |  4 | ZhuZL |   56 | M      | Pixie Jianfa  |
  +----+-------+------+--------+---------------+
  2 rows in set (0.00 sec)
  5.5. 授权给testuser对testdb库所有权限;

  mysql> CREATE USER 'testuser1'@'%'>  Query OK, 0 rows affected (0.00 sec)
  mysql> GRANT ALL PRIVILEGES ON testdb.* TO 'testuser1'@'%';
  Query OK, 0 rows affected (0.00 sec)
  mysql> SHOW GRANTS FOR  'testuser1'@'%';
  +---------------------------------------------------------------------------------+
  | Grants for testuser1@%  |
  +---------------------------------------------------------------------------------+

  | GRANT USAGE ON *.* TO 'testuser1'@'%'>  | GRANT ALL PRIVILEGES ON `testdb`.* TO 'testuser1'@'%'  |
  +---------------------------------------------------------------------------------+
  2 rows in set (0.00 sec)
  [root@jacktest ~]# mysql -u testuser1 -p -h10.109.131.208
  Enter password:
  Welcome to the MySQL monitor.  Commands end with ; or \g.

  Your MySQL connection>  Server version: 5.0.77 Source distribution
  mysql> select * from testdb.students
  mysql> SHOW DATABASES;
  +--------------------+
  | Database        |
  +--------------------+
  | information_schema |
  | test          |
  | testdb       |
  +--------------------+
  3 rows in set (0.00 sec)
  附件:
  php、mysql下载地址: http://mirrors.163.com/centos/5/os/i386/CentOS/
  ---end---


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-620149-1-1.html 上篇帖子: mysql 内存优化之关闭numa-roidba 下篇帖子: php新手之mysql 保留字问题
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表