实验环境为CentOS6.6。
一,准备工作
本次使用的mysql为mysql-5.5.42-linux2.6-i686所需的安装包可以去此网站下载,下载地址 http://mirrors.sohu.com/mysql/MySQL-5.5/
编译安装的目录:/usr/local/
二,编译安装
1、准备数据存放的文件系统
新建一个逻辑卷,并将其挂载至特定目录即可。这里创建逻辑卷的挂载目录为/mydata,而后创建/mydata/data目录做为mysql数据的存放目录。创建逻辑卷是为了方便数据的备份及转移,设置数据存放目录的大小。
[root@www ~]# fdisk /dev/sdb
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 4
First cylinder (1307-2610, default 1307):
Using default value 1307
Last cylinder, +cylinders or +size{K,M,G} (1307-2610, default 2610):
Using default value 2610
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (1307-2610, default 1307):
Using default value 1307
Last cylinder, +cylinders or +size{K,M,G} (1307-2610, default 2610): +8G
Command (m for help): t
Partition number (1-5): 5
Hex code (type L to list codes): 8e
Changed system type of partition 5 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x9f95503f
Device Boot Start End Blocks Id System
/dev/sdb1 1 1306 10490413+ 83 Linux
/dev/sdb4 1307 2610 10474380 5 Extended
/dev/sdb5 1307 2351 8393931 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@www ~]# partprobe /dev/sdb
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
[root@www ~]# partprobe /dev/sdb
[root@www ~]# pvcreate /dev/sdb5
Physical volume "/dev/sdb5" successfully created
[root@www ~]# vgcreate myvg /dev/sdb5 #创建为myvg的卷组
Volume group "myvg" successfully created
[root@www ~]# lvcreate -n mydata -L 5G myvg
Logical volume "mydata" created
[root@www ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
mydata myvg -wi-a----- 5.00g
[root@www ~]# mke2fs -j /dev/myvg/mydata
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
。。。。。。。。。。
[root@localhost ~]# mkdir /mydata
[root@localhost ~]# vim /etc/fstab #开机自动挂载
/dev/myvg/mydata /mydata ext4 defaults,noatime 0 0
[root@localhost ~]# mount -a #挂载
2、新建系统用户以其运行进程:
[root@www mysql]# groupdel mysql
[root@www mysql]# groupadd -r -g 306 mysql
[root@www mysql]# useradd -r -g 306 -u 306 mysql
[root@www mysql]# id mysql
uid=306(mysql) gid=306(mysql) groups=306(mysql)
3、安装并初始化mysql-5.5.42
注意,这里是以二进制格式进行安装的,平台为32位的,大家不要下错版本,对于下错版本这种傻逼问题带来的烦恼我是深有体验,以前不知道二进制格式是什么就去官网随便下载了个tar包,然后照着别人的方法安装,结果错误不断,并且还搜不到答案,弄得我着实头疼,最后才发现是下错文件了,下面说下怎么区分各种文件:
rpm格式很好区分,文件名就以rpm结尾,
二进制格式的包名字很长,都带有版本号、适应平台、适应的硬件类型等,
源码格式仅仅就是一个版本号的tar包,
希望各位不要下错版本。
[root@www ~]# tar xf mysql-5.5.42-linux2.6-i686.tar.gz -C /usr/local
[root@www ~]# cd /usr/local/
[root@www ~]# ln -sv mysql-5.5.42-linux2.6-i686 mysql
[root@www ~]# cd mysql
[root@www ~]# chown -R mysql:mysql .
[root@www ~]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data
如果执行上步命令出现如下问题,则说明下载的文件错误:
FATAL ERROR: Could not find my_print_defaults
The following directories were searched:
/usr/local/mysql/bin
/usr/local/mysql/extra
If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.
If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.
[root@www ~]# chown -R root . # 防止mysql被攻击后取得user权限
#数据默认放在data目录下。但是我们修改了数据的位置,不然应将data文件夹设置为可写的
4、为mysql提供主配置文件
[root@www ~]# cd /usr/local/mysql
[root@www ~]# cp support-files/my-large.cnf /etc/my.cnf #large.cnf为512M内存使用的
[root@www support-files]# vim /etc/my.cnf
#修改此文件中thread_concurrency的值为你的CPU个数乘以2,比如这里使用如下行:
thread_concurrency = 2
#线程并发量,每个线程用一个cpu
#另外还需要添加如下行指定mysql数据文件的存放位置:
datadir = /mydata/data
[root@www support-files]# service mysqld start
Starting MySQL...................... SUCCESS! #不知怎么回事,好长时间!
5、为mysql提供sysv服务脚本
[root@www ~]# cd /usr/local/mysql
[root@www ~]# cp support-files/mysql.server /etc/init.d/mysqld
[root@www ~]# chmod +x /etc/init.d/mysqld
添加至服务列表:
[root@www ~]# chkconfig --add mysqld
[root@www ~]# chkconfig mysqld on
而后就可以启动服务测试使用了。
为了使用mysql的安装符合系统使用规范,并将其开发组件导出给系统使用,这里还需要进行如下步骤:
6、输出mysql的man手册至man命令的查找路径:
编辑/etc/man.config,添加如下行即可:
[root@www ~]# vim /etc/man.config
43 MANPATH /usr/man
44 MANPATH /usr/share/man
45 MANPATH /usr/local/man
46 MANPATH /usr/local/share/man
47 MANPATH /usr/X11R6/man
48 MANPATH /usr/local/mysql/man ------->添加此行
7、输出mysql的头文件至系统头文件路径/usr/include:
这可以通过简单的创建链接实现:
[root@www mysql]# mkdir /usr/include/mysql
[root@www mysql]# ln -sv /usr/local/mysql/include /usr/include/mysql
8、输出mysql的库文件给系统库查找路径:
[root@www ~]# vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib ----->创建此文件添加此行
而后让系统重新载入系统库:
[root@www mysql]# ldconfig -v #重新读取库文件让其生效,实际是让操作系统重新建立库文件缓存
[root@www mysql]# ls -l /etc/ld.so.cache #缓存目录在此
-rw-r--r--. 1 root root 58810 May 15 06:59 /etc/ld.so.cache
9、修改PATH环境变量,让系统可以直接使用mysql的相关命令。
[root@www ~]# vim /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin/ ------>创建此文件添加此行
三,测试结果
[root@www ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.42-log MySQL Community Server (GPL) ----->5.5.42
mysql> use mysql;
mysql> select user,host,password from user;
+------+-----------------------+----------+
| user | host | password |
+------+-----------------------+----------+
| root | localhost | |
| root | localhost.localdomain | |
| root | 127.0.0.1 | |
| | localhost | |
| | localhost.localdomain | |
+------+-----------------------+----------+
5 rows in set (0.00 sec)
mysql> drop user ''@'localhost'; #删除匿名用户
Query OK, 0 rows affected (0.00 sec)
mysql> drop user ''@'localhost.localdomain';
Query OK, 0 rows affected (0.01 sec)
mysql> update user set password=PASSWORD('feiyu') where user='root'; #为root用户设定密码
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
说明已经安装成功了!
DevOps-田飞雨 》》转载请注明源地址
喜欢 (0)or分享 (0)