MySQL安裝目錄概要
- 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
- /etc/init.d/mysqld start
搭建LNMP環境
LAMP架構下,而後搭建LNMP架構
1.首先查看mysql是否啓動
ps aux |grep mysql
2.刪除目錄
rm -rf /usr/local/mysql/
3.刪除啓動的腳本
rm -rf /etc/init.d/mysqld
4.而後其餘步驟相同
- 這裏新建一個虛擬環境(這裏不是在lamp架構上搭建的,而是新建的一個環境)
- 而後進入到/usr/local/src目錄下
[root@hanfeng ~]# cd /usr/local/src
[root@hanfeng src]#
- 下載mysql安裝包
[root@hanfeng src]# wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
- 而後解壓安裝包
[root@hanfeng src]# tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
- 移動目錄並修更名稱——>這裏移動目錄到/usr/local/下時,必定不能有mysql目錄,(若已經有mysql目錄時,再去移動則會放到mysql目錄下面去,而不是去移動並修更名稱了)
[root@hanfeng src]# mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql
[root@hanfeng src]#
- 移動完後,檢查目錄
[root@hanfeng src]# ls /usr/local/mysql
bin data include man README share support-files
COPYING docs lib mysql-test scripts sql-bench
[root@hanfeng src]#
- 進入到/usr/local/mysql目錄下
[root@hanfeng src]# cd /usr/local/mysql
[root@hanfeng mysql]#
- 新建mysql用戶和/data/目錄——>這裏如果在lamp以前的基礎上作的話,須要rm -rf /data/mysql/*清空內容,(直接刪除mysql目錄也能夠。它會自動建立)
[root@hanfeng mysql]# useradd mysql
[root@hanfeng mysql]# mkdir /data/
[root@hanfeng mysql]#
- 初始化./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
- 初始化的過程目的,就是把mysql啓動所須要的目錄生成
[root@hanfeng 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 install -y perl-Data-Dumper
Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
yum install -y libaio
- 而後能夠echo $?檢查,或者看初始化的過程當中是否有兩個OK
[root@hanfeng mysql]# echo $?
0
[root@hanfeng mysql]#
- 拷貝配置文件cp support-files/my-default.cnf /etc/my.cnf
- 拷貝文件cp support-files/mysql.server /etc/init.d/mysqld
[root@hanfeng mysql]# cp support-files/mysql.server /etc/init.d/mysqld
- 編輯文件 /etc/init.d/mysqld,並配置
[root@hanfeng mysql]# vim /etc/init.d/mysqld
在文件中配置
basedir=/usr/local/mysql
datadir=/data/mysql
而後保存退出
- 啓動mysql服務
[root@hanfeng mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql/hanfeng.err'.
. SUCCESS!
[root@hanfeng mysql]#
- 查看服務是否啓動成功
[root@hanfeng mysql]# ps aux |grep mysql
root 2295 0.0 0.1 113252 1608 pts/0 S 22:41 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/hanfeng.pid
mysql 2403 1.9 44.6 973512 451180 pts/0 Sl 22:41 0:00 /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/hanfeng.err --pid-file=/data/mysql/hanfeng.pid
root 2429 0.0 0.0 112656 992 pts/0 R+ 22:41 0:00 grep --color=auto mysql
[root@hanfeng mysql]#
- 將mysql服務加入到服務列表中去,並設置開機啓動
[root@hanfeng mysql]# chkconfig --add mysqld
[root@hanfeng mysql]# chkconfig mysqld on
[root@hanfeng mysql]#
- 下次就能夠直接使用service關閉或啓動服務
[root@hanfeng mysql]# service mysqld stop
Shutting down MySQL.. SUCCESS!
[root@hanfeng mysql]# service mysqld start
Starting MySQL. SUCCESS!