[平台环境]CentOS6.5 i686 mysql-5.1.73.tar.gz源码包
一、安装前检查,确保开发工具包都已安装
# yum grouplist | grep Devel
# yum groupinstall "Development tools" -y
# rpm -qa | grep -i libtool
# yum -y install libtool
对于有些需要从光盘安装的,需挂载iso镜像:
(对于Virtualbox虚拟机,需要把iso文件加载到“存储”(第二IDE控制器主通道),然后执行#mount /dev/cdrom /mnt/iso即可)
二、创建mysql用户、组
# groupadd mysql
# useradd -g mysql -s /bin/bash -M -d /home/mysql mysql
# mkdir -p /usr/local/mysql
# mkdir -p /usr/local/mysql/data
三、解压安装包
# cp mysql-5.1.73.tar.gz /tmp
# cd /tmp
# tar -zxvf mysql-5.1.73.tar.gz
四、预编译配置
# cd mysql-5.1.73
# ./configure \
--prefix=/usr/local/mysql \
--localstatedir=/usr/local/mysql/data \
--sysconfdir=/etc/mysql/ \
--with-unix-socket-path=/usr/local/mysql/sock/mysql.sock \
--enable-assembler \
--enable-profiling \
--enable-thread-safe-client \
--with-mysqld-user=mysql \
--with-tcp-port=3306 \
--with-big-tables \
--without-debug \
--with-extra-charsets=utf8,gbk \
--with-charset=utf8 \
--with-collation=utf8_general_ci \
--with-embedded-server \
--enable-local-infile \
--with-plugins=innobase,myisam \
--with-server-suffix=-community \
--with-mysqld-ldflags=-all-static \
--with-client-ldflags=-all-static
[注意]:可能会出现"/bin/rm: cannot remove `libtoolT': No such file or directory"这样的报错。
其中一种解决办法是:# vi configure ,把$RM "$cfgfile" 这一行改成:$RM -f "$cfgfile",保存退出,重新执行。
五、编译安装(make && make install)
# make && make install
# cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
注:配置文件,有large,medium,small三个环境下的,根据机器性能选择,如果负荷比较大,可修改里面的一些变量的内存使用值
# /usr/local/mysql/bin/mysql_install_db --user=mysql
Installing MySQL system tables...
150205 2:22:30 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
OK
Filling help tables...
150205 2:22:31 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h inspB password 'new-password'
Alternatively you can run:
/usr/local/mysql/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/local/mysql/bin/mysqlbug script!
# chown -R mysql:mysql /usr/local/mysql/
六、添加服务
# cp /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysqld
# chmod 755 /etc/rc.d/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld off
# service mysqld start
# 或者
# /usr/local/mysql/bin/mysqld_safe &
七、安装后检测并修改root密码
# /usr/local/mysql/bin/mysqladmin version
# /usr/local/mysql/bin/mysqladmin ping
# ln -s /usr/local/mysql/bin/mysql /usr/bin/
# ln -s /usr/local/mysql/bin/mysqladmin /usr/bin/
设置root密码
# mysqladmin -u root password "YourPassword"
配置mysql库文件搜索路径
# echo "/usr/local/mysql/lib/mysql/" >>/etc/ld.so.conf
# ldconfig -v
八、清除空密码数据库用户,增加外部连接用户
# mysql -u root -p
mysql> grant all privileges on *.* to goopand@'%' identified by 'MyPassword';
mysql> flush privileges;
mysql> use mysql;
mysql> delete from user where password="";
mysql> exit;
说明:
grant <权限1>,<权限2>,...,<权限n> on <数据库名称>.<表名称> to <用户名>@<用户地址> identified by '<连接口令>';
放开防火墙对默认端口3306的限制
vi /etc/sysconfig/iptables , 添加一行:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
# service iptables restart