Mysql数据库安装方式

MySQL数据库安装方法有两种,一种是yum/rpm通过YUM源在线安装,另外一种是通过源码软件编译安装。

  • YUM方式安装MYSQL方法,执行命令:
yum install mysql-server mysql-devel mysql-libs -y CentOS6.x YUM安装

yum install mariadb-server mariadb mariadb-libs -y CentOS7.x YUM安装

    • 源码安装MYSQL5.5.20方法,通过cmake、make、make install三个步骤实现。
wget http://down1.chinaunix.net/distfiles/mysql-5.5.20.tar.gz

yum -y install gcc-c++ ncurses-devel cmake make perl gcc autoconf automake zlib libxml2 libxml2-devel libgcrypt libtool bison

tar -xzf mysql-5.5.20.tar.gz

cd mysql-5.5.20

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql55/ \

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \

-DMYSQL_DATADIR=/usr/local/mysql55/data/ \

-DSYSCONFDIR=/usr/local/mysql55/data/ \

-DMYSQL_USER=mysql \

-DMYSQL_TCP_PORT=3306 \

-DWITH_XTRADB_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_EXTRA_CHARSETS=1 \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DEXTRA_CHARSETS=all \

-DWITH_BIG_TABLES=1 \

-DWITH_DEBUG=0

make

make install

  • 源码安装MYSQL5.7.20方法,通过cmake、make、make install三个步骤实现。
wget http://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz

tar zxvf boost_1_59_0.tar.gz

mv boost_1_59_0 /usr/local/boost

yum -y install gcc-c++ ncurses-devel cmake make perl gcc autoconf automake zlib libxml2 libxml2-devel libgcrypt libtool bison

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql5/ \

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \

-DMYSQL_DATADIR=/data/mysql/ \

-DSYSCONFDIR=/etc \

-DMYSQL_USER=mysql \

-DMYSQL_TCP_PORT=3306 \

-DWITH_XTRADB_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_EXTRA_CHARSETS=1 \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DEXTRA_CHARSETS=all \

-DWITH_BIG_TABLES=1 \

-DWITH_DEBUG=0 \

-DDOWNLOAD_BOOST=1 \

-DWITH_BOOST=/usr/local/boost

make

make install

/usr/local/mysql5/bin/mysqld –initialize –user=mysql –basedir=/usr/local/mysql5 –datadir=/data/mysql

  • MYSQL源码安装参数详解
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql55     Cmake预编译;-DMYSQL_UNIX_ADDR=/tmp/mysql.sock                 MYSQL Socket通信文件位置;

-DMYSQL_DATADIR=/data/mysql                         MYSQL数据存放路径;

-DSYSCONFDIR=/etc                                     配置文件路径;

-DMYSQL_USER=mysql                                 MYSQL运行用户;

-DMYSQL_TCP_PORT=3306                             MYSQL监听端口;

-DWITH_XTRADB_STORAGE_ENGINE=1                 开启xtradb引擎支持;

-DWITH_INNOBASE_STORAGE_ENGINE=1             开启innodb引擎支持;

-DWITH_PARTITION_STORAGE_ENGINE=1             开启partition引擎支持;

-DWITH_BLACKHOLE_STORAGE_ENGINE=1             开启blackhole引擎支持;

-DWITH_MYISAM_STORAGE_ENGINE=1                 开启MyISAM引擎支持;

-DWITH_READLINE=1                                 启用快捷键功能;

-DENABLED_LOCAL_INFILE=1                         允许从本地导入数据;

-DWITH_EXTRA_CHARSETS=1                         支持额外的字符集;

-DDEFAULT_CHARSET=utf8                             默认字符集UTF-8;

-DDEFAULT_COLLATION=utf8_general_ci                 检验字符;

-DEXTRA_CHARSETS=all                             安装所有扩展字符集;

-DWITH_BIG_TABLES=1                             将临时表存储在磁盘上;

-DWITH_DEBUG=0                                    禁止调试模式支持;

make                                                编译;

make install                                         安装。

  • 将源码安装的Mysql数据库服务设置为系统服务,可以使用chkconfig管理,并启动MYSQL数据库,如图11-1所示:
cd /usr/local/mysql55/

\cp support-files/my-large.cnf /etc/my.cnf

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

chkconfig –add mysqld
chkconfig –level 35 mysqld on

mkdir -p /data/mysql

useradd mysql

/usr/local/mysql55/scripts/mysql_install_db –user=mysql –datadir=/data/mysql/ –basedir=/usr/local/mysql55/

ln -s /usr/local/mysql55/bin/* /usr/bin/

service mysqld restart

图11-1 查看MYSQL启动进程

  • 不设置为系统服务,也可以用源码启动方式。
cd /usr/local/mysql55

mkdir –p /data/mysql

useradd mysql

/usr/local/mysql55/scripts/mysql_install_db –user=mysql –datadir=/data/mysql/ –basedir=/usr/local/mysql55/

ln -s /usr/local/mysql55/bin/* /usr/bin/

/usr/local/mysql55/bin/mysqld_safe –user=mysql &