標籤:linux 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就不會,它會慢慢寫入磁碟再停止。資料量較大的話時間可能會久點,但是安全。
本文出自 “13348833” 部落格,請務必保留此出處http://13358833.blog.51cto.com/13348833/1968907
centos7下 LAMP環境搭建--mysql安裝