centos7下 LAMP环境搭建--mysql安装

安装MySQL

MySQL的几个常用安装包:rpm、源码、二进制免编译

cd /usr/local/src

wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz

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

实验流程

[[email protected] ~]# cd /usr/local/src/                  //建议安装的部署程序放在这个目录下

[[email protected] src]# uname -a                            //可以查看电脑是32位还是64位

Linux lyon-01 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

[[email protected] src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz                                   //下载64位的5.6版本的包。比较大,可能需要等会

[[email protected] src]# tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz      //解压

[[email protected] src]# mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql

//将MySQL的解压目录移动到/usr/local/下,并改名字为mysql

[[email protected] local]# cd mysql/                     //务必确保在此之前么有mysql目录

[[email protected] mysql]# ls

bin      data  include  man         README   share      support-files

COPYING  docs  lib      mysql-test  scripts  sql-bench

[[email protected] mysql]# useradd mysql                   增加用户mysql

[[email protected] mysql]# mkdir /data/                        创建存放数据的目录

[[email protected] mysql]#  ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql //初始化

FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:

Data::Dumper                      这里报了错,可以搜索,也可以yum list 模糊搜索

[[email protected] mysql]# yum list |grep perl |grep -i dumper

perl-Data-Dumper.x86_64                 2.145-3.el7                    base

perl-Data-Dumper-Concise.noarch         2.020-6.el7                    epel

perl-Data-Dumper-Names.noarch           0.03-17.el7                    epel

perl-XML-Dumper.noarch                  0.81-17.el7                    base

-------这里会有几个包,可以依次安装 也可以都安装

[[email protected] mysql]# yum install -y perl-Data-Dumper.x86_64  //这个包

[[email protected] mysql]#  ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

echo $?

[[email protected] mysql]# cp support-files/my-default.cnf  /etc/my.cnf

系统本身自带一个my.cnf的文件 我们改成如下即可:

[mysqld]

datadir=/data/mysql                         //只修改这里

socket=/tmp/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0

# Settings user and group are ignored when systemd is used.

# If you need to run mysqld under a different user or group,

# customize your systemd unit file for mariadb according to the

# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]

#log-error=/var/log/mariadb/mariadb.log    //注释

#pid-file=/var/run/mariadb/mariadb.pid         //注释

#

# include all files from the config directory

#

#!includedir /etc/my.cnf.d                     //注释

保存退出即可。

启动脚本部分

[[email protected] mysql]# ls support-files/

binary-configure  magic  my-default.cnf  mysqld_multi.server  mysql-log-rotate  mysql.server

[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld

[[email protected] mysql]# vi /etc/init.d/mysqld

修改这个地方即可

basedir=/usr/local/mysql

datadir=/data/mysql

保存退出

配置开机启动

[[email protected] mysql]# chkconfig --add mysqld

[[email protected] 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:关

服务启动 :

[[email protected] mysql]# service mysqld start

Starting MySQL.Logging to ‘/data/mysql/lyon-01.err‘.

.. SUCCESS!                     //出现success说明服务成功启动

[[email protected] mysql]# ps aux |grep mysql

root      4190  0.0  0.1  11760  1584 pts/1    S    15:09   0:00 /bin/sh /usr/local/mysql/bin/mysqd_safe --datadir=/data/mysql --pid-file=/data/mysql/lyon-01.pid

mysql     4325 10.0 44.6 973044 450676 pts/1   Sl   15:09   0:02 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/lyon-01.err --pid-file=/data/mysql/lyon-01.pid --socket=/tmp/mysql.sock

root      4353  0.0  0.0 112664   976 pts/1    S+   15:09   0:00 grep --color=auto mysql

[[email protected] mysql]# netstat -lnpt

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1384/sshd

tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1806/master

tcp6       0      0 :::3306                 :::*                    LISTEN      4325/mysqld

tcp6       0      0 :::22                   :::*                    LISTEN      1384/sshd

tcp6       0      0 ::1:25                  :::*                    LISTEN      1806/master

假设我们没有启动脚本   我们用下面这个方法启动

[[email protected] mysql]# service mysqld stop     //停止服务

Shutting down MySQL.. SUCCESS!

[[email protected] mysql]# ps aux |grep mysqld

root      4392  0.0  0.0 112664   972 pts/1    S+   15:17   0:00 grep --color=auto mysqld    //已经停掉了

[[email protected] mysql]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql &            //用这个命令,并放在后台执行

[1] 4401

[[email protected] mysql]# 170926 15:19:54 mysqld_safe Logging to ‘/data/mysql/lyon-01.err‘.

170926 15:19:55 mysqld_safe Starting mysqld daemon with databases from /data/mysql

[[email protected] mysql]# !ps

ps aux |grep mysqld                 //看下是否已经启动

root      4401  0.0  0.1 113256  1584 pts/1    S    15:19   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql

mysql     4524  1.4 44.5 973044 449500 pts/1   Sl   15:19   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=/data/mysql/lyon-01.err --pid-file=/data/mysql/lyon-01.pid --socket=/tmp/mysql.sock

root      4552  0.0  0.0 112664   976 pts/1    R+   15:21   0:00 grep --color=auto mysqld

[[email protected] mysql]# !net                  //看一下mysql的端口

netstat -lnpt

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1384/sshd

tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1806/master

tcp6       0      0 :::3306                 :::*                    LISTEN      4524/mysqld

tcp6       0      0 :::22                   :::*                    LISTEN      1384/sshd

tcp6       0      0 ::1:25                  :::*                    LISTEN      1806/master

如何关闭呢

[[email protected] support-files]# /etc/init.d/mysqld stop

或者  killall  mysqld

尽量不要  kill pid的方法实现,但是建议用killall 更安全

数据库的读写很快,如果你kill 掉的话,内存里的数据可能会丢失,但是killall就不会,它会慢慢写入磁盘再停止。数据量较大的话时间可能会久点,但是安全。

时间: 2024-08-28 08:44:49

centos7下 LAMP环境搭建--mysql安装的相关文章

linux下lamp环境搭建(apache安装,mysql安装,php安装)

1.卸载系统内置的LAMP环境 1)卸载httpd服务(内置Apache) ① 使用rpm指令查询安装的httpd服务 ② 卸载httpd服务 如果出现以上提示,代表系统默认不允许我们卸载软件,使用强制卸载 - - nodeps 依次卸载其他软件 2)卸载mysql服务 3)卸载php服务 2.LAMP环境安装注意事项 ① 必须把Linux系统中的内置AMP卸载干净 ② 注意软件的安装顺序 第一步:首先安装Apache环境 第二步:安装MySQL环境 第三步:安装PHP环境 3.Apache软件

Centos7下lamp环境搭建的小笔记

刚刚把校赛弄完,赛前在环境搭建上花了蛮多时间,也正好记一下笔记 0.首先更新源 清华大学开源镜像站的源 https://mirrors.tuna.tsinghua.edu.cn/help/centos/ 首先备份 CentOS-Base.repo sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak 将源内容写入 /etc/yum.repos.d/CentOS-Base.repo 更新软件包

转载自php100中文网 centos下lamp 环境搭建

学习PHP脚本编程语言之前,必须先搭建并熟悉开发环境,开发环境有很多种,例如LAMP.WAMP.MAMP等.这里我介绍一下LAMP环境的搭建,即Linux.Apache.MySQL.PHP环境. 一.首先安装操作系统 操作系统:centos6.3 IP地址:192.168.146.129 网关: DNS: 操作系统安装步骤,此处不在给出截图. 备注:服务器系统采用最小化安装,安装一下GCC编译工具和一个桌面即可.如下图所示: <a href="http://www.php100.com/u

ubuntu12.04下lamp环境搭建步骤

1 .安装apache2:sudo apt-get install apache2 安装完成后,运行如下命令重启apache:sudo /etc/init.d/apache2 restart,在浏览器中输入http://localhost或者http://127.0.0.1,会看到"It works!"说明apache安装成功. 2.安装php: sudo apt-get install libapache2-mod-php5 php5; 安装扩展php5-gd:sudo apt-ge

Centos7下LNMMP环境搭建

实验环境: Centos7_64 实验目的:在Centos7下实现源码安装nginx+mariadb+memcache+php均为最新版本 --2015.10.10 一.解决依赖关系yum install -y openssl-devel pcre-devel cmake 二.安装nginx groupadd -r nginx useradd -r -g nginx nginx tar -zxvf nginx-1.9.5.tar.gz cd nginx-1.9.5 ./configure --p

基于centOs7下appium环境搭建

事件背景: 前几日在群里看到关总说他的server端是搭建在linux环境下,包括对客户端与服务端的交互处理,感觉整体思路清晰可鉴,于是就想尝试,动手实践,接着从环境搭建开始搞起,于是就有了这篇文章,不得不吐槽下,这是段很深刻的回忆呀,历时1.5工作日,终于搞定环境搭建!! 依赖关联: ps:以我现在的为例,个别根据自己情况调整 JDK 1.8 Android SDK 1.0.40 nodejs 8.7 appium 1.9.1 一.安装jdk: 参考我之前写过的<ubuntu12.04 安装配

Mac 下LAMP环境搭建

在本地搭建LAMP Apache Mac OS自带Apache,所以只需要修改一些配置即可,配置文件为/etc/apache2/httpd.conf 修改根目录 DocumentRoot 添加 AddType Application/ x-httpd-php .php 用以支持php 支持后缀,端口等 php Mac自带php,起配置文件在/private/etc/php.ini,可以根据自身需要,修改配置文件等 mysql mysql需要自己下载安装,可以去其官网下载 安装之后默认root帐号

Centos下LAMP环境搭建

判断是否安装:rpm -qa|grep apache/php/mysql 安装APACHE Yum –y installhttpd 默认web根目录为/var/www/html 启动:service httpd start 备注:Apache启动之后会提示错误:       正在启动 httpd:httpd:Could not reliably determine the server's fully qualif domain name, using ::1 forServerName    

LAMP环境搭建+iTop安装(实测使用centos7更方便)

centos 6.7 basic server搭建apache+mariadb+php Apache 1.ifup ifcfg eth0,配置开机自动启动: 2.setup 设置dns 3.yum install vsftpd 4.修改vsftpd配置文件,两个配置文件中的root用户注释掉: 5.关闭selinux: # vi /etc/selinux/config 6.修改ftpd服务开机启动启动: 7.上传补丁: 8.打补丁: # rpm -ivh 1-ppl-0.10.2-11.el6.