实现:
yum安装相应的库,因为我这台机子还要安装nginx,php,所以以下的库都安装了
# 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
下载mysql,编译安装
# wget http://dl.gaingreat.com/mysql-5.1.38.tar.gz # /usr/sbin/groupadd mysql # /usr/sbin/useradd -s /sbin/nologin -M -g mysql mysql //添加mysql用户到mysql组,指定sh为/sbin/nologin,无家目录 # tar zxvf mysql-5.1.38.tar.gz# cd mysql-5.1.38/ # ./configure --prefix=/usr/local/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=partition,innobase,myisammrg # make && make install
更改mysql安装目录属性,初始化mysql
# mkdir -p /opt/mysql/data # mkdir /var/log/mysql # mkdir /usr/local/mysql/var //建立这个目录,不然/etc/init.d/mysqld start是会报错,因为默认my.cnf中innodb_data_home_dir和innodb_log_group_home_dir位置为/usr/local/mysql/var,可以修改目录位置也可以新建这个目录 # chown -R mysql:mysql /usr/local/mysql # chown -R mysql:mysql /opt/mysql/data # chown -R mysql:mysql /var/log/mysql # /usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/opt/mysql/data/ --user=mysql //这里datadir目录要与下面/etc/my.cnf里的datadir一致,不然会出现starting mysql. error manager of pid-file quit without updating file。具体原因可以通过查看mysql_error.log日志
拷贝配置文件到/etc/my.cnf
# cp -f /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf //将skip-locking 转换成skip-external-locking # sed -i ‘s/skip-locking/skip-external-locking/g‘ /etc/my.cnf # sed -i ‘s:#innodb:innodb:g‘ /etc/my.cnf
添加开机启动
# cp /usr/local/mysql/share/mysql/mysql.server /etc/init.d/mysqld # chmod 755 /etc/init.d/mysqld //添加执行权限 # ln -s /usr/local/mysql/lib/mysql /usr/lib/ # ln -s /usr/local/mysql/insclude/mysql /usr/include/ # chkconfig mysqld on //设置开机启动
修改my.cnf,在[mysqld]里面添加
log-error = /var/log/mysql/mysql_error.log pid-file = /var/log/mysql/mysql.pid datadir = /opt/mysql/data
启动mysql
# /etc/init.d/mysqld start
修改root的密码
# /usr/local/mysql/bin/mysqladmin -u root password ‘newpassword‘ # /usr/local/mysql/bin/mysql -u root -p //登陆mysql,删除默认帐号密码> use mysql;> delete from user where not (user=‘root‘) ;> delete from user where user=‘root‘ and password=‘‘;> drop database test;> DROP USER ‘‘@‘%‘; //这条没看出效果> flush privileges;
mysql服务的启动、关闭
# /etc/init.d/mysqld start# /etc/init.d/mysqld stop
本文出自 “小人志” 博客,请务必保留此出处http://johnchow.blog.51cto.com/3517015/1639296
原文:http://johnchow.blog.51cto.com/3517015/1639296