CentOS 5.6 mysql-5.5.19
创建mysql用户
useradd -s /sbin/nologin mysql
创建mysql安装目录
#mkdir /usr/local/mysql
#mkdir -p /data/mysql
#chown mysql.mysql -R /data/mysql/
安装camke mysql5.5以后通过cmake来编译的
#wget http://www.cmake.org/files/v2.8/cmake-2.8.3.tar.gz
#tar xzvf cmake-2.8.3.tar.gz
#cd cmake-2.8.3/
#./configure
#make
# make install
#或者:
#./bootstrap
#gmake
#gmake install
安装mysql 5.5.19
#tar xf mysql-5.5.19.tar.gz
#cd mysql-5.5.19
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DMYSQL_DATADIR=/data/mysql
-DMYSQL_UNIX_ADDR=/data/mysql/mysqld.sock
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DENABLED_LOCAL_INFILE=1 -DDEFAULT_CHARSET=utf8
-DDEFALUT_CHARSETS=all
-DDEFAULT_COLLATION=utf8-general_ci
-DMYSQL_USER=muysql
-DWITH_DEBUG=0
make && make install
# make -j 8 && make install
//开始编译并安装,-j 参数可选用来指定CPU核心数,可加快编译速度,服务器双路4核这里用了8
mysql配置文件
#cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf
#cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
#chmod +x /etc/init.d/mysqld
mysql初始化
#/usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/data/mysql/
#/etc/init.d/mysqld start
#/usr/local/mysql/bin/mysqladmin -u root password 'password'
#/usr/local/mysql/bin/mysql -uroot -p
如果报错,错误信息如下:
[root@localhost mysql-5.5.19]# bash scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/
Installing MySQL system tables...
120330 16:19:42 [ERROR] Unknown collation: 'utf8-general_ci'
120330 16:19:42 [ERROR] Aborting
120330 16:19:42 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete
Installation of system tables failed! Examine the logs in
/home/webserver/mysqldata/ for more information.
vi /etc/my.cnf
在[mysqld]下面添加
character_set_server=utf8
CMAKE参数参考
MAKE_INSTALL_PREFIX mysql的安装路径;
DEFAULT_CHARSET 默认的服务器编码,
DEFAULT_COLLATION 也是关于编码的
MYSQL_DATADIR data目录
MYSQL_TCP_PORT TCP/IP端口,3306
MYSQL_UNIX_ADDR unix的socket文件,默认/tmp/mysql.sock
WITH_xxx_STORAGE_ENGINE 编译静态的存储引擎xxx
WITHOUT_xxx_STORAGE_ENGINE Exclude storage engine xxx from build
WITH_EXTRA_CHARSETS 扩展字符集
WIHT_ZLIB zlib支持
常用的选项有下边这些:
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
#安装目录
-DMYSQL_DATADIR=/usr/local/mysql/data \
#数据库存放目录
-DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock \
#Unix socket 文件路径
-DWITH_MYISAM_STORAGE_ENGINE=1 \
#安装 myisam 存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
#安装 innodb 存储引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
#安装 archive 存储引擎
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
#安装 blackhole 存储引擎
-DWITH_PARTITION_STORAGE_ENGINE=1 \
#安装数据库分区
-DENABLED_LOCAL_INFILE=1 \
#允许从本地导入数据
-DWITH_READLINE=1 \
#快捷键功能
-DWITH_SSL=yes \
#支持 SSL
-DDEFAULT_CHARSET=utf8 \
#使用 utf8 字符
-DDEFAULT_COLLATION=utf8_general_ci \
#校验字符
-DEXTRA_CHARSETS=all \
#安装所有扩展字符集
-DMYSQL_TCP_PORT=3306 \
#MySQL 监听端口