linux下搭建LNMP(linux+nginx+mysql+php)环境之mysql5.5安装;
首先安装依赖包:
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers ntpd nmap patch cmake bison cgi* *-gd-* libtool-* gettext *libxml-devel libcurl-devel libevent libevent-devel net-snmp-devel lsof unzip
清除之前安装过的mysql;
rpm -e --nodeps mysql*
cd /usr/local/src
wget http://www.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.28.tar.gz/from/http://cdn.mysql.com/
tar -zxvf index
cd mysql-5.5.28
到这里发现没有cmake命令;安装cmake
cd ..
wget http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz
tar -zxvf cmake-2.8.4.tar.gz
cd cmake-2.8.4
./configure
make && make install
继续回来安装mysql,新建mysql用户和组
groupadd mysql
useradd -g mysql mysql
创建目录并设定权限
chmod +w /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
mkdir -p /var/mysql/data/
mkdir -p /var/mysql/log/
chown -R mysql:mysql /var/mysql/
mkdir -p /home/mysql/temp
chown -R mysql:mysql /home/mysql/temp
开始安装,用cmake编译mysql
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql-DMYSQL_DATADIR=/var/mysql/data
配置my.cnf
cd support-files/
cp my-huge.cnf /etc/my.cnf
vi /etc/my.cnf
//////////////////////////////////////////////////////////////////////////////////////////
[client]
password = root
port = 3306
socket = /usr/local/mysql/mysql.sock
[mysqld]
character-set-server = utf
user = mysql
port = 3306
socket = /usr/local/mysql/mysql.sock
basedir = /usr/local/mysql
datadir = /var/mysql/data
tmpdir = /home/mysql/temp
log-error = /var/mysql/log/error.log
pid-file = /var/mysql/mysql.pid
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8
///////////////////////////////////////////////////////////////////////////////////////////
初始化安装mysql数据库
cd /usr/local/mysql/scripts/
./mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/var/mysql/data --user=mysql
将mysql启动服务文件添加到init.d下,并设置为开机启动
cp /usr/local/src/mysql-5.5.28/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
vi /etc/init.d/mysqld
查找并修改:
basedir=/usr/local/mysql
datadir=/var/mysql/data
chkconfig --add mysqld
chkconfig --level 2345 mysqld on
最后启动mysql服务,进入客户端设置密码
service mysqld start
cd /usr/local/mysql/bin/
mysql -uroot -p
update mysql.user set password=password("root") where user=root;
flush privileges;