Redhat下MySQL5.5.20安装配置

mysql最新的版本都需要cmake编译安装,估计以后的版本也会采用这种方式,所以特地记录一下安装步骤及过程,以供参考。
注意:此安装是默认Redhat下已经安装了最新工具包,比如GNU make, GCC, Perl, libncurses5-dev,如果在编译安装过程中发现有缺失的工具包,先yum install单独下载安装再继续即可。

. linuxwget下载需要的软件,保存到目录/usr/local/src

wget ftp://mirror.switch.ch/mirror/mysql/Downloads/MySQL-5.5/mysql-5.5.20.tar.gz

wget http://www.cmake.org/files/v2.8/cmake-2.8.7.tar.gz

wget http://ftp.gnu.org/gnu/bison/bison-2.5.tar.gz


.安装cmake
cd /usr/local/src
tar zxvf cmake-2.8.7.tar.gz
cd cmake-2.8.7
./bootstrap
gmake
gmake install
cd ../

tar zxvf bison-2.5.tar.gz
cd bison-2.5
./configure
make
make install
cd ../

.编译安装MySQL 5.5.20
groupadd -g 1000 mysql
useradd -u 1000 -g mysql mysql
tar xvf mysql-5.5.20.tar.gz
cd mysql-5.5.20/

/usr/local/bin/cmake-DCMAKE_INSTALL_PREFIX=/opt/mysql \
-DMYSQL_UNIX_ADDR=/opt/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/opt/mysql/data \
-DSYSCONFDIR=/opt/mysql \
-DMYSQL_TCP_PORT=3306


-- Could NOT find Curses (missing:CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:82 (MESSAGE):
Curses library not found. Pleaseinstall appropriate package,
removeCMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name islibncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:117 (FIND_CURSES)
cmake/readline.cmake:213(MYSQL_USE_BUNDLED_READLINE)
CMakeLists.txt:250 (MYSQL_CHECK_READLINE)

yum install ncurses-devel
rm CMakeCache.txt
--这里重新开始做上面cmake操作即可
make
make install
chmod +w /opt/mysql
chown -R mysql:mysql /opt/mysql
ln -s /opt/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
mkdir -p /opt/mysql/data
chown -R mysql:mysql /opt/mysql/data
mkdir -p /opt/mysql/log
chown -R mysql:mysql /opt/mysql/log
cd support-files/

如果你的内存≤64m,复制my-small.cnf;内存64-128m,复制my-medium.cnf;内存128-512m,复制my-large.cnf;内存1-2g,复制my-huge.cnf;内存4g以上,复制my-innodb-heavy-4G.cnf
cp my-large.cnf /etc/my.cnf
cp mysql.server /etc/init.d/mysqld

. 配置启动 MySQL 5.5.20
1.
若有需要请先修改 mysql 的配置 my.cnf
vi /etc/my.cnf

[mysqld] 下添加
basedir = /opt/mysql
datadir = /opt/mysql/data

2.my.cnfmysql初始化安装

chmod +x/opt/mysql/scripts/mysql_install_db
/opt/mysql/scripts/mysql_install_db \
--defaults-file=/etc/my.cnf \
--basedir=/opt/mysql \
--datadir=/opt/mysql/data \
--user=mysql

3.
mysql加入开机启动
chmod +x /etc/init.d/mysqld
vi /etc/init.d/mysqld
(编辑此文件,查找并修改以下变量内容:)
basedir=/opt/mysql
datadir=/opt/mysql/data
chkconfig --add mysqld
chkconfig --level 345 mysqld on

4.
启动mysql
service mysqld start

5.
配置访问帐号root

/opt/mysql/bin/mysqladmin -uroot password zdsoft
/opt/mysql/bin/mysql -uroot -p
mysql>use mysql;
mysql>GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY 'zdsoft' with GRANT OPTION;

mysql>update user set password=password('zdsoft'); --所有用户都密码更新

mysql>FLUSH PRIVILEGES;
mysql>quit;


你可能感兴趣的:(redhat)