Linux—MySQL安装配置详解

1、MySQL是一个开放源码的小型关联式数据库管理系统,开发者为瑞典MySQL AB公司。MySQL被广泛地应用在Internet上的中小型网站中。由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,许多中小型网站为了降低网站总体拥有成本而选择了MySQL作为网站数据库。如果用Linux作为操作系统,Apache作为web服务器,MySQL作为数据库,PHP/Perl/Python作为服务器端脚本解释器就可以组合成稳定、免费、功能强大的网站系统,也就是所谓的LAMP组合,这篇文简单介绍一下MySQL的安装配置。

2、MySQL安装流程如下图:

Linux—MySQL安装配置详解

3、MySQL编译安装具体实现:

准备环境,由于SQL的数据量增长很快,MySQL数据库最好放在LVM上以便很好的进行扩展。

创建逻辑卷用来存放数据库

[root@localhost ~]# ls -l /dev/sdb1
brw-rw---- 1 root disk 8, 17 Mar 12 00:19 /dev/sdb1
[root@localhost ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created
[root@localhost ~]# vgcreate l23f /dev/sdb1
  Volume group "l23f" successfully created
[root@localhost ~]# lvcreate -L 2G -n l23 l23f
  Logical volume "l23" created
[root@localhost ~]# 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

Linux—MySQL安装配置详解

对逻辑卷进行格式化

[root@localhost ~]# mke2fs -t ext4 /dev/l23f/l23

准备数据库存放目录并挂载逻辑卷

[root@localhost ~]# mkdir -pv /data/mysqldata
mkdir: created directory `/data‘
mkdir: created directory `/data/mysqldata‘
[root@localhost ~]# mount /dev/l23f/l23 /data/mysqldata

Linux—MySQL安装配置详解

下载文件并解压

[root@localhost ~]# 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
[root@localhost ~]# 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
[root@localhost ~]# tar xf mysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local/
[root@localhost ~]# 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/‘
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql  mysql-5.5.33-linux2.6-x86_64  sbin  share  src

创建mysql用户和组,由于root权限太大所以非常不安全,需要建立mysql用户

[root@localhost local]# groupadd mysql
[root@localhost local]# useradd -g mysql mysql
[root@localhost local]# id mysql
uid=500(mysql) gid=500(mysql) groups=500(mysql)
[root@localhost local]#

设置权限

[root@localhost mysql]# chown -R mysql:mysql ./*
[root@localhost mysql]# chown -R :mysql /data/mysqldata/
[root@localhost 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
[root@localhost mysql]# ll /data/mysqldata/
total 16
drwx------ 2 root mysql 16384 Mar 12 00:34 lost+found

安装、配置

[root@localhost mysql]# scripts/mysql_install_db --datadir=/data/mysqldata/ --user=mysql

Linux—MySQL安装配置详解

配置服务脚本以及mysql配置文件

[root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf
[root@localhost mysql]# vim /etc/my.cnf

Linux—MySQL安装配置详解

添加服务,启动mysql

[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# chkconfig --list mysqld
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@localhost mysql]# service mysqld start
Starting MySQL                                             [  OK  ]
[root@localhost mysql]#

修改环境变量

[root@localhost local]# vim /etc/profile.d/mysql.sh
[root@localhost local]# . /etc/profile.d/mysql.sh
[root@localhost local]# service mysqld start
Starting MySQL                                             [  OK  ]
[root@localhost local]# service mysqld stop
Shutting down MySQL.                                       [  OK  ]
[root@localhost local]# service mysqld start
Starting MySQL..                                           [  OK  ]
[root@localhost local]#

安装完成,登陆进行测试

Linux—MySQL安装配置详解

Linux—MySQL安装配置详解Linux—MySQL安装配置详解为了开发时可以调用mysql进行如下设置

[root@localhost mysql]# ls
bin      data  include         lib  mysql-test  scripts  sql-bench
COPYING  docs  INSTALL-BINARY  man  README      share    support-files
[root@localhost mysql]# ln -sv /usr/local/mysql/include/ /usr/include/mysql
`/usr/include/mysql‘ -> `/usr/local/mysql/include/‘

库文件写入配置文件

[root@localhost mysql]# vim /etc/ld.so.conf.d/mysql.conf

Linux—MySQL安装配置详解

man文档写入配置文件

vim /etc/man.config

Linux—MySQL安装配置详解

[root@localhost mysql]# man mysql

Linux—MySQL安装配置详解

整个过程结束。。。。。。

本文出自 “海闊天空” 博客,请务必保留此出处http://il23f.blog.51cto.com/8620950/1381354

Linux—MySQL安装配置详解,布布扣,bubuko.com

Linux—MySQL安装配置详解

上一篇:怎么安装mysqlworkbench


下一篇:SQLServer创建分区表