Linux—MySQL安装配置详解
1、MySQL是一个开放源码的小型关联式数据库管理系统,开发者为瑞典MySQL AB公司。MySQL被广泛地应用在Internet上的中小型网站中。由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为了降低网站总体拥有成本而选择了MySQL作为网站数据库。如果用Linux作为操作系统,Apache作为web服务器,MySQL作为数据库,PHP/Perl/Python作为服务器端脚本解释器就可以组合成稳定、免费、功能强大的网站系统,也就是所谓的LAMP组合,这篇文简单介绍一下MySQL的安装配置。
2、MySQL安装流程如下图:
3、MySQL编译安装具体实现:
准备环境,由于SQL的数据量增长很快,MySQL数据库最好放在LVM上以便很好的进行扩展。
创建逻辑卷用来存放数据库
[[email protected] ~]# ls -l /dev/sdb1 brw-rw---- 1 root disk 8, 17 Mar 12 00:19 /dev/sdb1 [[email protected] ~]# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created [[email protected] ~]# vgcreate l23f /dev/sdb1 Volume group "l23f" successfully created [[email protected] ~]# lvcreate -L 2G -n l23 l23f Logical volume "l23" created [[email protected] ~]# lvs LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert l23 l23f -wi-a----- 2.00g root vg0 -wi-ao---- 20.00g swap vg0 -wi-ao---- 2.00g usr vg0 -wi-ao---- 10.00g var vg0 -wi-ao---- 20.00g
对逻辑卷进行格式化
[[email protected] ~]# mke2fs -t ext4 /dev/l23f/l23
准备数据库存放目录并挂载逻辑卷
[[email protected] ~]# mkdir -pv /data/mysqldata mkdir: created directory `/data' mkdir: created directory `/data/mysqldata' [[email protected] ~]# mount /dev/l23f/l23 /data/mysqldata
下载文件并解压
[[email protected] ~]# lftp 172.16.0.1 lftp 172.16.0.1:~> cd pub/Sources/6.x86_64/mysql/ lftp 172.16.0.1:/pub/Sources/6.x86_64/mysql> ls -rw-r--r-- 1 0 0 186839926 Aug 22 2013 mysql-5.5.33-linux2.6-x86_64.tar.gz -rw-r--r-- 1 0 0 307062424 Aug 22 2013 mysql-5.6.13-linux-glibc2.5-x86_64.tar.gz -rw-r--r-- 1 0 0 307176769 Oct 07 05:26 mysql-5.6.14-linux-glibc2.5-x86_64.tar.gz lftp 172.16.0.1:/pub/Sources/6.x86_64/mysql> get mysql-5.5.33-linux2.6-x86_64.tar.gz 186839926 bytes transferred in 25 seconds (7.07M/s) lftp 172.16.0.1:/pub/Sources/6.x86_64/mysql> bye [[email protected] ~]# ls -l mysql-5.5.33-linux2.6-x86_64.tar.gz -rw-r--r-- 1 root root 186839926 Aug 22 2013 mysql-5.5.33-linux2.6-x86_64.tar.gz [[email protected] ~]# tar xf mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local/ [[email protected] ~]# ln -sv /usr/local/mysql-5.5.33-linux2.6-x86_64/ /usr/local/mysql `/usr/local/mysql' -> `/usr/local/mysql-5.5.33-linux2.6-x86_64/' [[email protected] ~]# cd /usr/local/ [[email protected] local]# ls bin etc games include lib lib64 libexec mysql mysql-5.5.33-linux2.6-x86_64 sbin share src
创建mysql用户和组,由于root权限太大所以非常不安全,需要建立mysql用户
[[email protected] local]# groupadd mysql [[email protected] local]# useradd -g mysql mysql [[email protected] local]# id mysql uid=500(mysql) gid=500(mysql) groups=500(mysql) [[email protected] local]#
设置权限
[[email protected] mysql]# chown -R mysql:mysql ./* [[email protected] mysql]# chown -R :mysql /data/mysqldata/ [[email protected] mysql]# ll total 200 drwxr-xr-x 2 mysql mysql 4096 Mar 12 00:42 bin -rw-r--r-- 1 mysql mysql 17987 Jul 15 2013 COPYING drwxr-xr-x 3 mysql mysql 4096 Mar 12 00:42 data drwxr-xr-x 2 mysql mysql 4096 Mar 12 00:42 docs drwxr-xr-x 3 mysql mysql 4096 Mar 12 00:42 include -rw-r--r-- 1 mysql mysql 134493 Jul 15 2013 INSTALL-BINARY drwxr-xr-x 3 mysql mysql 4096 Mar 12 00:42 lib drwxr-xr-x 4 mysql mysql 4096 Mar 12 00:42 man drwxr-xr-x 10 mysql mysql 4096 Mar 12 00:42 mysql-test -rw-r--r-- 1 mysql mysql 2496 Jul 15 2013 README drwxr-xr-x 2 mysql mysql 4096 Mar 12 00:42 scripts drwxr-xr-x 27 mysql mysql 4096 Mar 12 00:42 share drwxr-xr-x 4 mysql mysql 4096 Mar 12 00:42 sql-bench drwxr-xr-x 3 mysql mysql 4096 Mar 12 00:42 support-files [[email protected] mysql]# ll /data/mysqldata/ total 16 drwx------ 2 root mysql 16384 Mar 12 00:34 lost+found
安装、配置
[[email protected] mysql]# scripts/mysql_install_db --datadir=/data/mysqldata/ --user=mysql
配置服务脚本以及mysql配置文件
[[email protected] mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld [[email protected] mysql]# cp support-files/my-large.cnf /etc/my.cnf
[[email protected] mysql]# vim /etc/my.cnf
添加服务,启动mysql
[[email protected] mysql]# chkconfig --add mysqld [[email protected] mysql]# chkconfig --list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off [[email protected] mysql]# service mysqld start Starting MySQL [ OK ] [[email protected] mysql]#
修改环境变量
[[email protected] local]# vim /etc/profile.d/mysql.sh [[email protected] local]# . /etc/profile.d/mysql.sh [[email protected] local]# service mysqld start Starting MySQL [ OK ] [[email protected] local]# service mysqld stop Shutting down MySQL. [ OK ] [[email protected] local]# service mysqld start Starting MySQL.. [ OK ] [[email protected] local]#
安装完成,登陆进行测试
[[email protected] mysql]# ls bin data include lib mysql-test scripts sql-bench COPYING docs INSTALL-BINARY man README share support-files [[email protected] mysql]# ln -sv /usr/local/mysql/include/ /usr/include/mysql `/usr/include/mysql' -> `/usr/local/mysql/include/'
库文件写入配置文件
[[email protected] mysql]# vim /etc/ld.so.conf.d/mysql.conf
man文档写入配置文件
vim /etc/man.config
[[email protected] mysql]# man mysql
整个过程结束。。。。。。
转载于:https://blog.51cto.com/il23f/1381354