MySQL-5.5编译安装
一、安装前准备
1.1下载MySQL安装包
1
2
|
wget http:
//wwwNaNake
.org
/files/v2
.8
/cmake-2
.8.10.2.
tar
.gz
wget
ftp
:
//ftp
.ntu.edu.tw
/tmp/MySQL/Downloads/MySQL-5
.5
/mysql-5
.5.32.
tar
.gz
|
1.2 安装相关的包
1.2.1 cmake软件
1
|
cd
/root/tools
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
tar
-zxvf cmake-2.8.10.2.
tar
.gz
cd
cmake-2.8.10.2
.
/bootstrap
# 执行时出错,缺少依赖
---------------------------------------------
CMake 2.8.10.2, Copyright 2000-2012 Kitware, Inc.
C compiler on this system is: cc
---------------------------------------------
Error when bootstrapping CMake:
Cannot
find
appropriate C++ compiler on this system.
Please specify one using environment variable CXX.
See cmake_bootstrap.log
for
compilers attempted.
---------------------------------------------
Log of errors:
/root/tools/cmake-2
.8.10.2
/BootstrapNaNk/cmake_bootstrap
.log
|
1
2
3
4
5
|
#解决办法:安装g++和ncurses-devel
yum -y
install
gcc-c++ ncurses-devel cmake;
#重新安装编译
.
/bootstrap
gmake && gmake
install
|
二、开始安装mysql
1.1 创建用户和组
1
2
|
groupadd mysql
useradd
mysql -s
/sbin/nologin
-M -g mysql
|
1.2 解压编译MySQL
1
2
3
|
cd
/root/tools
tar
zxf mysql-5.5.32.
tar
.gz
cd
mysql-5.5.32
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
cmake . -DCMAKE_INSTALL_PREFIX=
/application/mysql-5
.5.32 \
-DMYSQL_DATADIR=
/application/mysql-5
.5.32
/data
\
-DMYSQL_UNIX_ADDR=
/application/mysql-5
.5.32
/tmp/mysql
.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0
|
1
|
make
&&
make
install
|
1.3添加链接
1
|
ln
-s
/application/mysql-5
.5.32/
/application/mysql
|
三、初始化配置pysql
1.1查看默认模板配置文件
1
|
ll support-files
/my
*cnf
|
2.1选择配置文件
1
|
/bin/cp
support-files
/my-small
.cnf
/etc/my
.cnf
|
测试环境选择小的,生成环境可以根据硬件选择,例如:my-innodb-h-heavy-4G.cnf
3.1配置环境变量
1
2
|
echo
"export PATH=/application/mysql/bin:$PATH"
>>
/etc/profile
tail
-l
/etc/profile
|
1
2
|
source
/etc/profile
echo
$PATH
|
4.1初始化数据文件
1
2
3
|
mkdir
-p
/application/mysql/data
#建立mysql数据文件目录(已有不用创建)
chown
-R mysql.mysql
/application/mysql/data/
#授权mysql用户访问mysql的安装目录
chown
-R 1777
/tmp/
#调整/tmp权限,否则初始化会错误
|
1
2
|
cd
/application/mysql/scripts/
.
/mysql_install_db
--basedir=
/application/mysql/--datadir
=
/application/mysql/data/
--user=mysql
|
1
2
3
|
/bin/cp
support-files
/mysql
.server
/etc/init
.d
/mysqld
chmod
+x
/etc/init
.d
/mysqld
/etc/init
.d
/mysqld
start
|
四、数据库简单优化(删除多余的用户)
1.1进入数据库
1.2删除多余用户
1
2
3
4
|
mysql>
select
user,host from mysql.user;
mysql> delete from mysel.user where user=’ ’;
mysql> delete from mysql.user where host=
'::1'
;
mysql> delete from mysql.user wherehost=
'CentOS'
;
|
1.3查看databases
1
2
|
mysql> show databases;
mysql> drop database
test
;
|
2.1增加密码
1
|
/application/mysql//bin/mysqladmin
-u root password
'centos'
|
3.1设置开机启动
1
2
|
chkconfig mysqld on
chkconfig --list mysqld
|
4.1删除全部,添加额外管理员
1
2
|
>delete from mysql.user;
>grant all privileges on *.*to system@’locahost’identified by ‘centos’ with grant option;
|
5.1mysql登陆
1
|
mysql -uroot -p
|
五、可能用到的命令
1、查看系统版本
1
2
|
cat
/etc/redhat-release
uname
–m
|
2、修改yum源
选择添加的源
1
2
|
wget -O
/etc/yum
.repos.d
/CentOS-Base
.repo
http:
//mirrors
.aliyun.com
/repo/Centos-6
.repo
|
1
|
yum makecache
|
3、安装rz、sz
1
|
yum
install
lrzsz
|
4、修改字符集
1
|
vi
/etc/sysconfig/i18n
|
本文转自 运维小当家 51CTO博客,原文链接:http://blog.51cto.com/solin/1888798,如需转载请自行联系原作者