安装mysql源码包:
(1).安装cmake
(mysql5.5以后是通过cmake来编译的)
下载解压cmake-2.8.5.tar.gz
tar zxf cmake-2.8.12.2.tar.gz -C /usr/local/src
cd /usr/local/src/cmake-2.8.12.2
./configure --prefix=/usr/local/cmake
make && make install
export PATH=/usr/local/cmake/bin:$PATH
【必须依赖包】
cmake make gcc ncurses-devel gcc-c++
(2).安装mysql
groupadd mysql
useradd -s /sbin/nologin -g mysql mysql
cd /app/mysql_soft
tar xf mysql-5.6.17.tar.gz
cd mysql-5.6.17
cmake \
-DCMAKE_INSTALL_PREFIX=/app/mysql \
-DMYSQL_DATADIR=/app/mysql/data \
-DMYSQL_UNIX_ADDR=/app/mysql/data/mysql.sock \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_USER=mysql \
-DWITH_DEBUG=0
make && make install
chown -R mysql.mysql /app/mysql
cd /app/mysql/scripts/
./mysql_install_db --user=mysql --basedir=/app/mysql --datadir=/app/mysql/data
cd ..
cd support-files/
cp mysql.server /etc/rc.d/init.d/mysql
cp my-default.cnf /etc/my.cnf
chkconfig --add mysql
chkconfig mysql on
service mysql start
ln -s /app/mysql/bin/* /usr/bin/
mysqladmin -u root password ‘mysql‘ #设置数据库root密码为mysql#
##############修改配置文件##############
vi /etc/my.cnf
[mysqld]
datadir=/app/mysql/data
socket =/app/mysql/data/mysql.sock
lower_case_table_names=1
character-set-server=utf8
collation-server=utf8_general_ci
[client]
default-character-set=utf8
[mysql.server]
user=mysql
basedir=/app/mysql
default-character-set=utf8
[mysqld_safe]
err-log=/app/mysql/errlog/mysqld.log
注意:
如果报:
mysqladmin: connect to server at ‘localhost‘ failed
error: ‘Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2)‘
Check that mysqld is running and that the socket: ‘/var/lib/mysql/mysql.sock‘ exists!
[client] 增加
socket =/app/mysql/data/mysql.sock