此帖为读者介绍怎样在Mac下使用源码编译MySQL,注意:需要xcode。
不废话,开工。
首先,切换到root用户。
su - root
修改.bash_login文件,注入环境变量。
vim ~/.bash_login
cat ~/.bash_login
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql_5.1/bin:$PATH"
使配置生效。
. ~/.bash_login
创建存放源码的目录。
mkdir -p ~/src
cd ~/src/
获得源码。
wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.73.tar.gz
解压源码。
tar zxvf mysql-5.1.73.tar.gz
cd mysql-5.1.73
配置MySQL。
CC=gcc CFLAGS="-O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti"
./configure --prefix=/usr/local/mysql_5.1 --with-extra-charsets=gbk,gb2312,utf8 --enable-thread-safe-client --enable-local-infile --enable-shared --with-plugins=partition,innobase,innodb_plugin,myisam
编译和安装MySQL。
make
make install
cd /usr/local/mysql_5.1/
初始化MySQL。
./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql_5.1 --datadir=/usr/local/mysql_5.1/data
更改权限。
chown -R mysql:mysql /usr/local/mysql_5.1
拷贝启动脚本。
cp support-files/mysql.server /usr/local/bin/mysql_5.1
增加可执行权限。
chmod +x /usr/local/bin/mysql_5.1
修改启动脚本。
vim /usr/local/bin/mysql_5.1
修改内容如下。
basedir=/usr/local/mysql_5.1
datadir=/usr/local/mysql_5.1/data
拷贝配置文件,修改之。主要修改basedir和datadir。
cp support-files/my-medium.cnf /etc/my.cnf
vim /etc/my.cnf
grep "^#\|^$" /etc/my.cnf -v
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
basedir = /usr/local/mysql_5.1
datadir = /usr/local/mysql_5.1/data
port = 3306
socket = /tmp/mysql.sock
skip-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
log-bin=mysql-bin
binlog_format=mixed
server-id = 1
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
启动MySQL。
mysql_5.1 start
制定安全策略。
/usr/local/mysql_5.1/bin/mysql_secure_installation
在提示信息下做如下选择:
Change the root password? [Y/n] Y
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
重启MySQL,然后登录。
mysql_5.1 restart
mysql -uroot -p
Server version: 5.1.73 Source distribution
mysql> SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 5.1.73 |
+-----------+
1 row in set (0.00 sec)
mysql> exit
Bye
Enjoy!
该贴由hui.chen转至本版2014-12-1 10:01:32