添加mysql组和mysql用户
[root@centos mysql]# groupadd mysql
[root@centos mysql]# useradd -g mysql mysql
[root@centos mysql]# useradd -g mysql mysql
编译与安装
tar -zxvf mysql-5.1.35.tar.gz
./configure \
--prefix=/usr/local/mysql \
--localstatedir=/data/mysql/data \ mysql数据目录
--enable-assembler \
--with-mysqld-ldflags=-rdynamic \
--with-client-ldflags=-all-static \
--with-plugins=innobase,partition \
--with-extra-charsets=none \
--enable-thread-safe-client \
--prefix=/usr/local/mysql \
--localstatedir=/data/mysql/data \ mysql数据目录
--enable-assembler \
--with-mysqld-ldflags=-rdynamic \
--with-client-ldflags=-all-static \
--with-plugins=innobase,partition \
--with-extra-charsets=none \
--enable-thread-safe-client \
--with-client-ldflags=-all-static \ 以纯静态方式编译客户端
--with-mysqld-ldflags=-all-static 以纯静态方式编译服务端
--with-mysqld-ldflags=-all-static 以纯静态方式编译服务端
make && make install
--enable-thread-safe-client \以线程方式编译客户端
mysql目录权限设置
mkdir /usr/local/mysql/var
mkdir /var/run/mysqld
chmod +w /usr/local/mysql/
chown -R mysql:mysql /usr/local/mysql/
chown -R mysql:mysql /usr/local/mysql/
chown -R mysql:mysql /var/run/mysqld
cp /usr/local/mysql/share/mysql/my-innodb-heavy-4G.cnf /etc/my.cnf
以mysql用户初始化数据库表
/usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/data --user=mysql
--datadir=/data/mysql/data 定义mysql数据存放目录
注意:如果把数据目录定义到其它目录里,得先修改/etc/my.cnf文件,加上以下二行
[mysqld]
# generic configuration options
port = 3306
socket = /tmp/mysql.sock
port = 3306
socket = /tmp/mysql.sock
# wb config
basedir = /usr/local/mysql 字义mysql程序目录
datadir = /data1/mysql/data 定义数据目录
datadir = /data1/mysql/data 定义数据目录
在对数据库进行初始化表,不然mysql数据库启动会报错.
启动mysql服务
/usr/local/mysql/bin/mysqld_safe --user=mysql --datadir=/data/mysql/data (指定数据库目录)
/usr/local/mysql/bin/mysqld_safe --user=mysql 2>&1 > /dev/null &