一:安装mysql

1.web服务器上安装mysql

yum -y remove mysql mysql-server  ##卸载mysqlrpm

确认yum源指定到ftp

[root@www ~]# cat /etc/yum.repos.d/centos.repo

[local]

name=local

baseurl=ftp://192.168.100.100/centos6

enabled=1

gpgcheck=0

wKiom1g4U-yxiTWUAAAVN9sI7wE340.png-wh_50 

yum -y install ncurses-*

wKiom1g4U_OyPYzcAAAXRh1PoIo132.png-wh_50 

lftp ftp.linuxfan.cn  ##下载mysqlcmake

(连接一台FTP服务器下载所需安装包

lftp ftp.linuxfan.cn:/tools> get cmake-2.8.6.tar.gz mysql-5.5.22.tar.gz

wKioL1g4VCewQ77mAAAN9EGlnZQ044.png-wh_50 

2.解压cmake,安装基础环境

tar zxvf /root/cmake-2.8.6.tar.gz -C /usr/src/

(解压cmake安装包并释放至/usr/src/目录下)

cd /usr/src/cmake-2.8.6

wKioL1g4VC-g_baWAAAplvJHBfs164.png-wh_50 

3.配置,编译安装cmake

./configure &&gmake &&gmake install

(过程冗长不截图)

echo $?(查看编译成功与否)

 wKioL1g4VFPxqUmfAAAFsYcqKqg856.png-wh_50

4.解压mysql

tar zxvf /root/mysql-5.5.22.tar.gz -C /usr/src/

(解压mysql安装包并释放至/usr/src/

cd /usr/src/mysql-5.5.22/

wKiom1g4VEjCztK-AAApOoVHfcQ244.png-wh_50 

5.使用cmake进行配置mysql

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql   #指定安装目录\

-DDEFAULT_CHARSET=utf8   #指定字符集为utf8 \

-DDEFAULT_COLLATION=utf8_general_ci   ##指定字符校验 \

-DWITH_EXTRA_CHARSETS=all   ##支持额外字符集\

-DSYSCONFDIR=/etc/  ##指定配置文件位置

&&make &&make install   #编译安装

(编译过程冗长不予截图)echo $?查看上命令是否执行成功

wKioL1g4VIaBZInuAAAIEpGJB_U115.png-wh_50 

ls  /usr/local/mysql  ##验证安装目录

wKiom1g4VI-zd8oQAAAS0k75CxU665.png-wh_50

 

.配置mysql

1.复制配置文件

cp /usr/src/mysql-5.5.22/support-files/my-medium.cnf /etc/my.cnf

wKioL1g4VJWgFVweAAALHr87LyA768.png-wh_50 

2.添加系统服务

cp /usr/src/mysql-5.5.22/support-files/mysql.server /etc/init.d/mysqld

chmod +x /etc/init.d/mysqld

chkconfig --add mysqld

chkconfig mysqld  on

wKiom1g4VJ2j6DXEAAAIZ0fk1UQ368.png-wh_50 

3.优化PATH路径,执行命令时方便,单引号双引号都行

echo 'export PATH=$PATH:/usr/local/mysql/bin'  >>/etc/profile

wKioL1g4VKTDEa6yAAAJ1AgpiI4297.png-wh_50

source /etc/profile  ##执行文件

reboot

 

4.初始化mysql,创建用户,赋权

userdel -r mysql  ##如果用户已经存在则删除,如果不存在不管

useradd -M -s /sbin/nologin mysql

chown -R mysql:mysql /usr/local/mysql

/usr/local/mysql/scripts/mysql_install_db  \

--basedir=/usr/local/mysql \

--datadir=/usr/local/mysql/data --user=mysql

--basedir=安装目录,--datadir=数据库存放目录

5.启动mysql,并设置为开机启动

/etc/init.d/mysqld start

chkconfig mysqld on

6.修改密码

mysqladmin -u root password '123123'

7.登录mysql

mysql -uroot -p123123  ##登录,也可以用-h选项指定服务器的ip地址进行远程登录

quit

wKioL1g4VKzgi6OUAAAqA9ZeSOA021.png-wh_50