11月9日任务

11.1 LAMP架构介绍

LANP=Linux(操作系统)+Apache(httpd真正的名字  web服务软件)+MySQL(存储,存储数据、字符串)+PHP(脚本语言,做网站为主,现主流是手机或者app调接口,php用户开始缩减)
2777d1abe5d6dcc117235bc0c3f1ba65830.jpg
PHP网站(Google、淘宝、百度、51cto博客、猿课论坛)
f388432fd457b07af472c60992e873ab856.jpg
注:现在流行Python  Java Go
三个角色可以在一台机器、也可以分开( httpd和PHP要在一起  mysql单独
 
httpd、PHP、MySQL三者如何工作
PHP是以模块的形式与Apache结合在一起,Apache不能喝mysql直接打交道, PHP模块去mysql中拿数据,拿到数据结果交给Apache,Apache交给用户
PHP模块去mysql中拿数据为 动态请求
动态请求:
访问网站,用户在浏览器中输入网址,登陆请求交给Apache,由Apache检查请求是动态还是静态,如果用户是登陆请求需要把用户名、密码提交给Apache,Apache去数据库中比对用户名密码是否正确,通过php模块与数据mysql打交道,首先在数据库中查询用户密码,然后php做对比,如果对Apache会反馈登陆状态
静态请求:
访问网站时图片等通过Apache在静态文件(linux服务器某个目录某个文件)中获取,直接反馈给用户
 
注:MySQL中不能存储文件存储图片,存储字符串、数据
484b841709e59bc7ec1148f50019a1614d7.jpg
 
 
 
11.2 MySQL、MariaDB介绍
MySQL是一个关系型数据库,由mysql ab公司开发,mysql在2008年被sun公司(java、jdk)收购(10亿刀),2009年sun公司被oracle公司(金融企业需要oracle数据库, 小型机使用 UNIX系统常用)收购(74亿刀) 
MySQL官网 https://www.mysql.com  最新版本5.7GA/8.0DMR 
MySQL5.6变化比较大,5.7性能上有很大提升 
Mariadb为MySQL的一个分支,官网 https://mariadb.com/最新版本10.2 
MariaDB主要由SkySQL公司(现更名为MariaDB公司)维护,SkySQL公司由MySQL原作者带领大部分原班人马创立. 
Mariadb5.5版本对应MySQL的5.5,10.0对应MySQL5.6  
Community 社区版本(开源),Enterprise 企业版(收费,提供服务),GA(Generally Available)指通用版本,在生产环境中用的(稳定版本,一般使用版本),DMR(Development Milestone Release)开发里程碑发布版(技术突破版本),RC(Release Candidate)发行候选版本(GA的候选,未发布,稳定版本),Beta开放测试版本(bug/缺陷,开放测试),Alpha内部测试版本(内测)
 
 
 
11.3/11.4/11.5 MySQL安装
5.6以及以前版本,初始密码为空。 5.7版本看它提示,有个随机密码。
 
MySQL的几个常用安装包:rpm(yum  无法定义安装路径,默认装在/usr/下)、源码(./config cmake  极致性能自己编译)、二进制免编译(发布之前在linux服务器上编译,编译后放置在一个文件下去打包压缩,不需要花长时间编译配置) 
cd /usr/local/src 
tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz 
mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql 
cd /usr/local/mysql 
useradd mysql 
mkdir /data/ 
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql 
cp support-files/my-default.cnf  /etc/my.cnf 
cp support-files/mysql.server /etc/init.d/mysqld 
vi /etc/init.d/mysqld   定义basedir和datadir
/etc/init.d/mysqld start
 
查看系统平台
[root @test mysql]# uname -a
Linux test 3.10.0-862.14.4.el7.x86_64 #1 SMP Wed Sep 26 15:12:11 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
下载mysql包
mysql 8.0二进制包         http://mirrors.163.com/mysql/Downloads/MySQL-8.0/mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz
[root @test ~]# cd /usr/local/src/
c45a3462ee1b03bc0758f552635c6cd985a.jpg
解压
[root @test src]# tar -Jxvf mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz
30f95ffa29e4d4bf545849cd01b9f954b65.jpg
将解压的包移至运行目录
[root @test src]# mv mysql-8.0.12-linux-glibc2.12-x86_64 /usr/local/mysql
[root@test src]# cd /usr/local/mysql/
2d7f52257f0e6ff8b5b1de23b53c974d7d4.jpg
 
创建数据库用户
[root@test mysql]# useradd mysql
[root@test mysql]# useradd -r -g mysql mysql
创建数据化目录(存放mysql数据)
[root@test mysql]# mkdir /data/
修改当前目录用户
[root@test mysql]# chown -R mysql:mysql .
 
模糊搜索
[root@test mysql]# yum list |grep perl |grep -i dumper
perl-Data-Dumper.x86_64                  2.145-3.el7                   @anaconda
perl-Data-Dumper-Concise.noarch          2.020-6.el7                   epel     
perl-Data-Dumper-Names.noarch            0.03-17.el7                   epel     
perl-Data-TreeDumper.noarch              0.40-19.el7                   epel     
perl-XML-Dumper.noarch                   0.81-17.el7                   base
 
初始化
[root@test mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
fc808a9acc77eb0b50e1216f390c028f084.jpg
 
注:这个命令和mysql5.7之前的命令不一样了,之前命令是:bin/mysql_install_db --user=mysql,但是之后的版本已经被mysqld --initialize替代
 
注:mysql5.7版本之上会初始化话一个密码,在这里要记住这个初始化密码,在下面初次登录会用上。
root@localhost: nWO%f_J,O6eP
5fb70b2520dd159fb244781bac58922a727.jpg
 
拷贝配置文件和启动脚本
mysql模板配置文件(mysql8.0无配置文件模板)
[root@test mysql]# vim /etc/my.cnf(系统自带)
注:
[root@test mysql]# rpm -qf /etc/my.cnf
mariadb-libs-5.5.60-1.el7_5.x86_64
修改
[mysqld]
datadir=/data/mysql
socket=/tmp/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
998f5e37303e7d7db2c593b101beacac4d2.jpg
 
[root@test mysql]# cp /etc/my.cnf ./support-files/my-default.cnf/
 
启动脚本
[root@test mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@test mysql]# vim !$
vim /etc/init.d/mysqld
修改:
basedir=/usr/local/mysql
datadir=/data/mysql
1f94840835e6e85d2a8ccfa3b6c824a3a9e.jpg
 
权限修改
[root@test mysql]# chmod 755 /etc/init.d/mysqld
 
开机启动
[root@test mysql]# chkconfig --add mysqld
[root@test mysql]# chkconfig --list
 
注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。
 
      要列出 systemd 服务,请执行 'systemctl list-unit-files'。
      查看在具体 target 启用的服务请执行
      'systemctl list-dependencies [target]'。
 
mysqld             0:关    1:关    2:开    3:开    4:开    5:开    6:关
netconsole         0:关    1:关    2:关    3:关    4:关    5:关    6:关
network            0:关    1:关    2:开    3:开    4:开    5:开    6:关
 
启动服务
[root@test mysql]# service mysqld start
Starting MySQL.Logging to '/data/mysql/test.err'.
.. SUCCESS!
[root@test mysql]# ps aux |grep mysqld
root     31803  0.0  0.0  11816  1616 pts/0    S    13:35   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/test.pid
mysql    31930  4.3  9.6 1796420 375616 pts/0  Sl   13:35   0:01 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=test.err --pid-file=/data/mysql/test.pid --socket=/tmp/mysql.sock
root     31985  0.0  0.0 112720   980 pts/0    S+   13:36   0:00 grep --color=auto mysqld
[root@test mysql]# netstat -lntp |grep mysqld
tcp6       0      0 :::33060                :::*                    LISTEN      31930/mysqld        
tcp6       0      0 ::: 3306                 :::*                    LISTEN      31930/mysqld  
 
后台命令行启动
[root@test mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql &
[1] 32070
[root@test mysql]# 2018-11-09T05:41:50.455701Z mysqld_safe Logging to '/data/mysql/test.err'.
2018-11-09T05:41:50.511435Z mysqld_safe Starting mysqld daemon with databases from /data/mysql
 
[root@test mysql]# !ps
ps aux |grep mysqld
root     32070  0.1  0.0 113308  1632 pts/0    S    13:41   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql
mysql    32199  6.1  9.3 1796276 364120 pts/0  Sl   13:41   0:01 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=test.err --pid-file=test.pid --socket=/tmp/mysql.sock
root     32249  0.0  0.0 112720   980 pts/0    S+   13:42   0:00 grep --color=auto mysqld
 
修改初始化密码
[root@test mysql]# /usr/local/mysql/bin/mysql -uroot -pnWO%f_J,O6eP
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.12
 
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
 
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 
mysql> alter user 'root'@'localhost' identified by '123';
Query OK, 0 rows affected (0.09 sec)
 
注:mysql两个引擎:innodb  myisam(存储空间比较小)

转载于:https://my.oschina.net/u/3803396/blog/2874088

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值