1、安装编译环境
<font face="新宋体">1</font> | yum install <font face="新宋体">gcc gcc-c++ autoconf automake ncurses-devel </font> |
2、下载,解压缩
<font face="新宋体">1</font> | <font face="新宋体">wget </font><font face="新宋体">http://mysql.mirror.tw/Downloads/MySQL-5.1/mysql-5.1.45.</font> tar .gz |
<font face="新宋体">2</font> | <font face="新宋体">tar</font> -xzvf mysql-5.1.45. tar .gz |
3、编译
<font face="新宋体">1</font> | CFLAGS= "-O3" <font face="新宋体">CXX=gcc CXXFLAGS="-O3 -felide-constructors \ </font> |
<font face="新宋体">2</font> | <font face="新宋体">-fno-exceptions -fno-rtti" ./configure \ </font> |
<font face="新宋体">3</font> | --prefix=/usr/ local /mysql -- enable -assembler \ |
<font face="新宋体">4</font> | --with-unix-socket-path=/usr/ local /mysql/tmp/mysql.sock \ |
<font face="新宋体">5</font> | <font face="新宋体">--with-mysqld-ldflags=-all-static \ </font> |
<font face="新宋体">6</font> | <font face="新宋体">--with-client-ldflags=-all-static \ </font> |
<font face="新宋体">7</font> | <font face="新宋体">--with-extra-charsets=all \ </font> |
<font face="新宋体">8</font> | <font face="新宋体">--without-debug --with-charset=utf8 \ </font> |
<font face="新宋体">9</font> | <font face="新宋体">--with-collation=utf8_general_ci \ </font> |
<font face="新宋体">10</font> | --with-pthread -- enable -static \ |
<font face="新宋体">11</font> | -- enable -thread-safe-client |
完成后会提示"Thank you for choosing MySQL!"
<font face="新宋体">1</font> | <font face="新宋体">make</font> |
最后会提示“make all win…”
<font face="新宋体">1</font> | <font face="新宋体">make</font> <font face="新宋体">install</font> |
4、添加用户,安装数据库
<font face="新宋体">1</font> | <font face="新宋体">useradd</font> <font face="新宋体">mysql </font> |
<font face="新宋体">2</font> | <font face="新宋体">passwd</font> mysql #设置密码,例如mysql123 |
<font face="新宋体">3</font> | |
<font face="新宋体">4</font> | <font face="新宋体">cd</font> /usr/ local /mysql/ |
<font face="新宋体">5</font> | <font face="新宋体">chown</font> <font face="新宋体">-R mysql:mysql ./ </font> |
<font face="新宋体">6</font> | |
<font face="新宋体">7</font> | <font face="新宋体">#安装数据库,添加默认mysql配置 </font> |
<font face="新宋体">8</font> | <font face="新宋体">./bin/mysql_install_db --user=mysql </font> |
<font face="新宋体">9</font> | <font face="新宋体">cp</font> <font face="新宋体">share/mysql/my-medium.cnf /etc/my.cnf</font> |
4、配置、开机自启动
<font face="新宋体">1</font> | <font face="新宋体">#经过上述配置后,mysql应该就可以正常启动了 </font> |
<font face="新宋体">2</font> | <font face="新宋体">./bin/mysqld_safe --user=mysql & </font> |
<font face="新宋体">3</font> | |
<font face="新宋体">4</font> | <font face="新宋体">#下面我们来设置开机启动mysql </font> |
<font face="新宋体">5</font> | kill 掉上述测试进程(一般是两个mysqld_safe是一个shell,它来启动mysqld的daemon) |
<font face="新宋体">6</font> | <font face="新宋体">cp</font> <font face="新宋体">share/mysql/mysql.server /etc/init.d/mysqld </font> |
<font face="新宋体">7</font> | <font face="新宋体">chkconfig --add mysqld </font> |
<font face="新宋体">8</font> | <font face="新宋体">chkconfig --level 2345 mysqld on </font> |
<font face="新宋体">9</font> | <font face="新宋体">#之后可以用service mysqld start启动,开机会自动启动</font> |
5、my.cnf参数调优
<font face="新宋体">1</font> | <font face="新宋体">vim /etc/my.cnf</font> |
6、安全配置
<font face="新宋体">1</font> | <font face="新宋体">#设置root密码 </font> |
<font face="新宋体">2</font> | <font face="新宋体">mysqladmin -u root password ‘new-password’ </font> |
<font face="新宋体">3</font> | |
<font face="新宋体">4</font> | <font face="新宋体">#删除test数据库、匿名帐户 </font> |
<font face="新宋体">5</font> | <font face="新宋体">mysql -u root -p </font> |
<font face="新宋体">6</font> | mysql> DROP DATABASE test ; [删除 test 数据库] |
<font face="新宋体">7</font> | mysql> DELETE FROM mysql.user WHERE user = '' ; [删除匿名帐户] |
<font face="新宋体">8</font> | <font face="新宋体">mysql> FLUSH PRIVILEGES; [重载权限]</font> |
7、小内存优化
只要不开InnoDB,my-medium.cnf 一般可以保证很小的内存占用和较高的性能了,具体的MySQL内存优化待续。