mysql安装方式分为源代码安装和软件包安装;软件包安装简单,源代码安装定制性强。由于软件包安装简单,这里不再赘述。已源代码安装为主


2.1 安装兼容性软件包

yum -y install cmake ncurses-devel gccgcc-c++ autoconf automake zlib libxml libgcrypt libtool

2.2 安装前的准备

同步服务器时钟(硬件时钟要与本地服务器时间一致)

(1)hwclock --hctosys

(2)ntpdate pool.ntp.org

clock -w

创建mysql用户和组

useradd -r -s /sbin/nologin mysql

创建mysql数据目录,并修改权限

mkdir /data/mysql -p

chown -R mysql:mysql /data/mysql

chmod 755 -R /data/mysql

上传/下载mysql源码包

cd /usr/lobal/src


解压源代码包

tar -zxvf mysql-5.7.2-m12.tar.gz


2.3配置编译mysql

cd mysql-5.7.2-m12

cmake \

-DCMAKE_BUILD_TYPE:STRING=Release \

-DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql\

-DCOMMUNITY_BUILD:BOOL=ON \

-DENABLED_PROFILING:BOOL=ON \

-DENABLE_DEBUG_SYNC:BOOL=OFF \

-DINSTALL_LAYOUT:STRING=STANDALONE \

-DMYSQL_DATADIR:PATH=/data/mysql \

-DMYSQL_MAINTAINER_MODE:BOOL=OFF \

-DWITH_EMBEDDED_SERVER:BOOL=ON \

-DWITH_EXTRA_CHARSETS:STRING=all \

-DWITH_SSL:STRING=bundled \

-DWITH_UNIT_TESTS:BOOL=OFF \

-DWITH_ZLIB:STRING=bundled \

-DENABLE_DTRACE=OFF


make && make install

(时间比较长)


2.4安装mysql

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

chmod -R 755 /usr/local/mysql

chown -R mysql:mysql /var/lib/mysql

chmod -R 755 /var/lib/mysql

ln -s/usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/.


vim /etc/my.cnf

[mysqld]

datadir=/data/mysql

socket=/var/lib/mysql/mysql.sock

user=mysql

# Disabling symbolic-links is recommendedto prevent assorted security risks

symbolic-links=0


[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/lib/mysql/mysqld.pid


[client]

socket=/var/lib/mysql/mysql.sock


./scripts/mysql_install_db --user=mysql--basedir=/usr/local/mysql --datadir=/data/mysql

2.5配置文件

添加启动项

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

vim /etc/init.d/mysqld

basedir=/usr/local/mysql

datadir=/data/mysql

chmod +x /etc/init.d/mysqld

chkconfig --add mysqld

chkconfig mysqld on

vim /root/.bash_profile

PATH=$PATH:$HOME/bin:/usr/local/mysql/bin


source ~/.bash_profile


2.6 启动数据库,初始化mysql密码

service mysqld start

mysqladmin -u root password mysql


2.7测试数据是否成功

mysql -u root –pmysql

select version();               #查看版本

status                       #还是查看版本