wget http://mirrors.sohu.com/mysql/MySQL-6.0/MySQL-server-6.0.10-0.glibc23.i386.rpmwget http://mirrors.sohu.com/mysql/MySQL-6.0/MySQL-client-6.0.10-0.glibc23.i386.rpmwget http://mirrors.sohu.com/apache/httpd-2.2.16.tar.gz
#卸载Mysqlrpm -qa|grep -i mysql rpm -ev MySQL-server-4.0.14-0 MySQL-client-4.0.14-0#彻底删除rm -rf /var/lib/mysqlrm -f /etc/my.cnf
#安装yum -y install gcc
groupadd mysqluseradd -g mysql mysql[yum -y install gcc+ gcc-c++]./configure --prefix=/opt/mysql --with-charset=utf8 --with-extra-charsets=all --with-tcp-port=3306 --with-unix-socket-path=/opt/mysql/var/mysql.sock --with-mysqld-user=mysql --with-federated-storage-engine --with-named-curses-libs=/usr/lib/libncurses.so.5 --without-plugin-falconmakemake install
scripts/mysql_install_db
cp support-files/my-huge.cnf /opt/mysql/var/my.cnf
======================
用 MySQL 有年头了,写篇简单的文档来记录下自己的常用安装和配置过程。本文旨在介绍如何在 Linux 系统上安装 MySQL 数据库服务器,以及基本配置。本文仅仅提供一份快速指南,请访问 MySQL 官方网站获取详细安装、配置指南。
OS: Red Hat Enterprise Linux AS 3.0MySQL: 5.0.22
源码 tarball 放置在 /home/huangys , 安装目的地是/opt/mysql
1. 准备
创建一个用户来运行 MySQL 守护进程。# groupadd mysqlg# useradd –g mysqlg –M –s /sbin/nologin mysqld
解包# cd /home/huangys# tar zxvf mysql-5.0.22.tar.gz
2. 配置编译选项
# cd mysql-5.0.22# ./configure --prefix=/opt/mysql --with-charset=utf8 --with-extra-charsets=all --with-tcp-port=3306 --with-unix-socket-path=/tmp/mysql.sock --with-mysqld-user=mysqld --with-federated-storage-engine
选项说明:--prefix=/opt/mysql 将MySQL安装到目录/opt/mysql下 --with-charset=utf8 指定缺省字符集为utf8--with-extra-charsets=all 将MySQL所有支持的字符集编译进来--with-tcp-port=3306 指定此MySQL实例将监听TCP 3306端口--with-unix-socket-path=/tmp/mysql.sock 指定UNIX socket文件的路径(为绝对路径)--wih-mysqld-user=mysqld 指定用来运行MySQL守护进程的用户--with-federated-storage-engine 支持federated存储引擎
--with-plugins=innobase 支持innobase数据库(5.1+,默认为空)
--without-debug \去除debug模式 --with-extra-charsets=gb2312 \添加gb2312中文字符支持 --enable-assembler \使用一些字符函数的汇编版本 --without-isam \去掉isam表类型支持 现在很少用了 isam表是一种依赖平台的表 (5.0以前)--without-innodb \去掉innodb表支持 innodb是一种支持事务处理的表,适合企业级应用 5.0以前)--with-pthread \强制使用pthread库(posix线程库) --enable-thread-safe-client \以线程方式编译客户端 --with-client-ldflags=-all-static \ --with-mysqld-ldflags=-all-static \以纯静态方式编译服务端和客户端
通过指令 configure --help 可以查看全部选项信息。
----prefix 必须指定
--with-unix-socket-path 最好指定自己的路径
优化编译:
1. -static 13% --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static静态链接提高13%性能2. -pgcc 1% CFLAGS="-O3 -mpentiumpro -mstack-align-double" CXX=gcc \ CXXFLAGS="-O3 -mpentiumpro -mstack-align-double \ -felide-constructors -fno-exceptions -fno-rtti"如果是Inter处理器,使用pgcc提高1%性能3. Unix Socket 7.5% --with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock使用unix套接字链接提高7.5%性能,所以在windows下mysql性能肯定不如unix下面4. --enable-assembler 允许使用汇编模式(优化性能)
如:./configure --prefix=/opt/aimcpro10/mysql-5.1.45 --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --with-unix-socket-path=/opt/aimcpro10/mysql-5.1.45/mysql.sock--enable-assembler --with-charset=utf8 --with-extra-charsets=gbk --with-plugins=innobase,myisam
3. 编译、安装
# make# make install
4. 初始化
# scripts/mysql_install_db这将会在安装目录 /opt/mysql 下创建 MySQL 的数据目录 var
5. 配置
在 MySQL 提供的支持文件中复制一个合适的配置档到 MySQL 数据目录中,并命名为 my.cnf# cp support-files/my-huge.cnf /opt/mysql/var/my.cnf
主要修改点在 [mysqld] 配置块中:
指定允许的最大包尺寸:max_allowed_packet = 2M
指定最大连接数(默认为100):max_connections = 1000
指定服务器端字符集:character_set_server = utf8
强制指定连接使用的字符集:init_connect = 'set names utf8'(注意:若连接时使用的是 super user ,则此项不会被执行,MySQL 文档对此有详细解释。)
指定安装目录和数据目录:basedir = /opt/mysql2/datadir = /opt/mysql2/var/
忽略Berkeley DB:skip-bdb(同理,若也打算忽略 InnoDB,则使用 skip-innodb)
配置InnoDB:innodb_data_home_dir = /opt/mysql2/var/innodb_data_file_path = ibdata1:500M;ibdata2:50M:autoextendinnodb_log_group_home_dir = /opt/mysql2/var/innodb_log_arch_dir = /opt/mysql2/var/innodb_buffer_pool_size = 384Minnodb_additional_mem_pool_size = 20Minnodb_log_file_size = 100Minnodb_log_buffer_size = 8Minnodb_flush_log_at_trx_commit = 1innodb_lock_wait_timeout = 50
完成编辑此配置档后,记得顺便修改一下 MySQL 数据目录的 ownership:# cd /opt/mysql# chown –Rc mysqld.mysqlg var
6. 控制脚本
MySQL提供了一个脚本文件,可以用来方便地控制MySQL守护进程。# cp support-files/mysql.server /opt/mysql/bin/mysqlctl# cd /opt/mysql/bin# chmod 755 mysqlctl
启动:# /opt/mysql/bin/mysqlctl start停止:# /opt/mysql/bin/mysql stop
注意,若启用了 InnoDB 存储引擎,那么第一次启动 MySQL 服务器时,速度会比较慢,因为需要分配在配置档中定义的空间、生成相应的数据文件、日志文件等。
7. Security
安全问题在哪里都是很重要的,特别是对于初安装的新系统而言,尤其如此。
MySQL 往往携带有四个缺省用户,分别是 'root'@'localhost', 'root'@'%', ''@'localhost', ''@'%'.除了第一个本地root,其他三个(任意来源的root,以及两个匿名用户)都应该删除:
mysql> use mysqlmysql> delete from user where user='';mysql> delete from user where user='root' and host='%';
这唯一保留的用户 root@localhost 的密码默认为空,当然不好。为它加上密码:
# /opt/mysql/bin/mysqladmin -uroot -hlocalhost -P3306 -p password my_pass
指令中的 my_pass 就是设定的密码,注意,不要用单引号把它括起来。
8. Appendix
[root@tbox2 root]# cat /etc/redhat-releaseRed Hat Enterprise Linux AS release 3 (Taroon)
[root@tbox2 root]# uname -aLinux tbox2.test.net 2.4.21-4.ELsmp #1 SMP Fri Oct 3 17:52:56 EDT 2003 i686 i686 i386 GNU/Linux
[root@tbox2 root]# rpm -qa | grep gcclibgcc-ssa-3.5ssa-0.20030801.41gcc-g77-3.2.3-20gcc-ssa-3.5ssa-0.20030801.41gcc-objc-ssa-3.5ssa-0.20030801.41compat-gcc-c++-7.3-2.96.122compat-gcc-7.3-2.96.122gcc-c++-3.2.3-20gcc-gnat-3.2.3-20gcc-objc-3.2.3-20gcc-c++-ssa-3.5ssa-0.20030801.41gcc-java-ssa-3.5ssa-0.20030801.41libgcc-3.2.3-20gcc-3.2.3-20gcc-java-3.2.3-20gcc-g77-ssa-3.5ssa-0.20030801.41
[root@tbox2 root]# rpm -qa | grep glibcglibc-headers-2.3.2-95.3glibc-common-2.3.2-95.3glibc-utils-2.3.2-95.3glibc-kernheaders-2.4-8.34glibc-devel-2.3.2-95.3compat-glibc-7.x-2.2.4.32.5glibc-2.3.2-95.3glibc-profile-2.3.2-95.3
[root@tbox2 root]# /opt/mysql/bin/mysql --version/opt/mysql/bin/mysql Ver 14.12 Distrib 5.0.22, for pc-linux-gnu (i686) using EditLine wrapper
END.
--------------------------------------------------------------------------------------------------------------------
./configure --prefix=/home/jack/mysql/ --with-unix-socket-path=/home/jack/mysql/mysql.sockmakemake installcp /usr/local/share/mysql/my-large.cnf /home/jack/mysql/my.cnfcd /home/jack/mysqlbin/mysql_install_dbbin/mysqld_safe &
********************************************************************** ********************************************************************** ********************************************************************** 手工安装mysql 1.改路径参数mysqld_safe mysqld_multi mysqlaccess mysql_upgrade_shell mysql_install_db mysqlbug mysql_fix_privilege_tables mysql_config (还要改mysql.sock) msql2mysql mysql_fix_privilege_tables mysql_install_db mysqld_safe 把这些文件里的路径,例如 :"/export/nfs10/builder/aimc3rd/mysql5/" 改为实际的路径 使用命令: :%s/\/export\/nfs10\/builder\/aimc3rd\/mysql5/\/opt\/aimm\/aimm\/mysql5 2.复制~/mysql5/share/mysql/my-medium.cnf ~/mysql5/.my.cnf 然后修改参数 [client] #password = your_password port = 3336 socket = /opt/aimm/aimm/mysql5/mysql.sock default-character-set = utf8 3.初始化数据库,执行脚本mysql_install_db 4.启动数据库 ./bin/mysqld_safe --defaults-file=./.my.cnf 5.连接数据库,新建用户aimm/aimm /mysql -h127.0.0.1 -P3336 -uroot -p grant all on *.* to aimm@"%" identified by "aimm" ---改密码:mysql> update user set Password=Password('aimc1234') where User='aiuum'; ---mysql> FLUSH PRIVILEGES; mysql> select * from user where user = ''; mysql> delete from user where user = ''; -------------------------------------------------------------- -------------------------------------------------------------- mysql编译参数详解
./configure \--prefix=/usr/local/mysql \--enable-assembler \--without-debug \--with-charset=utf8 \--with-extra-charsets=all \--with-pthread \--enable-thread-safe-client \--enable-local-infile \--with-client-ldflags=-all-static \--with-mysqld-ldflags=-all-static \--with-big-tables \--without-innod \--without-isam 2;--with-ssl \--with-embedded-server \
--enable-assembler \使用一些字符函数的汇编版本--without-debug \去除debug模式--with-charset=utf8 \--with-extra-charsets=complex字符支持--with-pthread \强制使用pthread库(posix线程库)--enable-thread-safe-client \以线程方式编译客户端--with-client-ldflags=-all-static \以纯静态方式编译客户端--with-mysqld-ldflags=-all-static \以纯静态方式编译服务端--with-big-tablesThere is a limit of 232 (~4.295E+09) rows in a MyISAM table. If you build MySQL with the --with-big-tables option, the row limitation is increased to (232)2 (1.844E+19) rows--without-innodb \去掉innodb表支持,innodb是一种支持事务处理的表,适合企业级应用--enable-local-infile #让mysql支持从本地文件 导入数据库--without-isam \去掉isam表类型支持,现在很少用了,isam表是一种依赖平台的表--with-embedded-server #编译成embedded MySQL library (libmysqld.a)
--------------------------------------
MySQL编译调整优化简明指南
http://blog.chinaunix.net/u1/36506/showart_432783.html