mysql 5.4编译_CentOS 5.4 x86_64 编译安装 MySQL 完全笔记

大前提,你的Linux系统要搭建好GCC的编译环境。使用CentOS的话可以:yum -y install gccyum -y install gcc-c++

添加MySQL用户组和用户groupadd mysqluseradd -g mysql mysql

MySQL编译安装依赖的软件包:cd /tmpwget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.7.tar.gztar zxvf ncurses-5.7.tar.gzcd ncurses-5.7./configure --prefix=/usr --with-shared --without-debugmakemake install

修改MySQL最大连接数,解开MySQL的原代码,进入里面的sql目录修改mysqld.cc找到下面一行:

{"max_connections", OPT_MAX_CONNECTIONS,"The number of simultaneous clients allowed.", (gptr*) &max_connections,(gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 151, 1, 16384, 0, 1,0},

把它改为:

{"max_connections", OPT_MAX_CONNECTIONS,"The number of simultaneous clients allowed.", (gptr*) &max_connections,(gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 1500, 1, 16384, 0, 1,0},

编译安装MySQL:

cd /tmpwget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.2-m2.tar.gztar -zvxf mysql-5.5.2-m2.tar.gzcd mysql-5.5.2-m2CFLAGS="-O3" CXX=gcc CXXFLAGS="-O3 -felide-constructors -fno-exceptions -fno-rtti -fomit-frame-pointer -ffixed-ebp"./configure --prefix=/usr/local/mysql --enable-assembler --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=all --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --with-plugins=partition,innobase,myisammrgmakemake install在CentOS上安装mysql时,可能会停顿一段时间(mysql-test),多等等就过去了

安装完成后,修改目录权限:chmod +w /usr/local/mysqlchown -R mysql:mysql /usr/local/mysql

建立一些必要的目录:mkdir -p /usr/local/mysql/datamkdir -p /usr/local/mysql/binlogmkdir -p /usr/local/mysql/relaylogchown -R mysql:mysql /usr/local/mysql

使用mysql用户帐号的身份建立数据表(也可以说初始化mysql的数据库):/usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql

创建MySQL的配置文件,配置文件名通常为my.cnf:vi /usr/local/mysql/my.cnf输入以下内容并保存:[client]character-set-server = utf8port    = 3306socket = /tmp/mysql.sock

[mysqld]character-set-server = utf8replicate-ignore-db = mysqlreplicate-ignore-db = testreplicate-ignore-db = information_schemauser    = mysqlport    = 3306socket = /tmp/mysql.sockbasedir = /usr/local/mysqldatadir = /usr/local/mysql/datalog-error = /usr/local/mysql/mysql_error.logpid-file = /usr/local/mysql/mysql.pidopen_files_limit    = 10240back_log = 600max_connections = 5000max_connect_errors = 6000table_cache = 614external-locking = FALSEmax_allowed_packet = 32Msort_buffer_size = 1Mjoin_buffer_size = 1Mthread_cache_size = 300thread_concurrency = 8query_cache_size = 512Mquery_cache_limit = 2Mquery_cache_min_res_unit = 2kdefault-storage-engine = MyISAMthread_stack = 192Ktransaction_isolation = READ-COMMITTEDtmp_table_size = 246Mmax_heap_table_size = 246Mlong_query_time = 3log-slave-updateslog-bin = /usr/local/mysql/binlog/binlogbinlog_cache_size = 4Mbinlog_format = MIXEDmax_binlog_cache_size = 8Mmax_binlog_size = 1Grelay-log-index = /usr/local/mysql/relaylog/relaylogrelay-log-info-file = /usr/local/mysql/relaylog/relaylogrelay-log = /usr/local/mysql/relaylog/relaylogexpire_logs_days = 30key_buffer_size = 256Mread_buffer_size = 1Mread_rnd_buffer_size = 16Mbulk_insert_buffer_size = 64Mmyisam_sort_buffer_size = 128Mmyisam_max_sort_file_size = 10Gmyisam_repair_threads = 1myisam_recover

interactive_timeout = 120wait_timeout = 120

skip-name-resolvemaster-connect-retry = 10slave-skip-errors = 1032,1062,126,1114,1146,1048,1396

#master-host     =   192.168.1.2#master-user     =   username#master-password =   password#master-port     = 3306

server-id = 1

innodb_additional_mem_pool_size = 16Minnodb_buffer_pool_size = 512Minnodb_data_file_path = ibdata1:256M:autoextendinnodb_file_io_threads = 4innodb_thread_concurrency = 8innodb_flush_log_at_trx_commit = 2innodb_log_buffer_size = 16Minnodb_log_file_size = 128Minnodb_log_files_in_group = 3innodb_max_dirty_pages_pct = 90innodb_lock_wait_timeout = 120innodb_file_per_table = 0

#log-slow-queries = /usr/local/mysql/slow.log#long_query_time = 10

[mysqldump]quickmax_allowed_packet = 32M

创建管理MySQL数据库的shell脚本:vi /usr/local/mysql/mysql

输入以下内容并保存(这里的用户名root和密码123456接下来的步骤会创建):

#!/bin/sh

mysql_port=3306

mysql_username="root"

mysql_password="123456"

function_start_mysql()

{

printf "Starting MySQL...\n"

/bin/sh /usr/local/mysql/bin/mysqld_safe--defaults-file=/usr/local/mysql/my.cnf 2>&1 > /dev/null &

}

function_stop_mysql()

{

printf "Stoping MySQL...\n"

/usr/local/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /tmp/mysql.sock shutdown

}

function_restart_mysql()

{

printf "Restarting MySQL...\n"

function_stop_mysql

sleep 5

function_start_mysql

}

function_kill_mysql()

{

kill -9 $(ps -ef | grep 'bin/mysqld_safe'| grep ${mysql_port} | awk'{printf $2}')

kill -9 $(ps -ef | grep 'libexec/mysqld'| grep ${mysql_port} | awk'{printf $2}')

}

if [ "$1"="start"];then

function_start_mysql

elif [ "$1"="stop"];then

function_stop_mysql

elif [ "$1"="restart"];then

function_restart_mysql

elif [ "$1"="kill"];then

function_kill_mysql

else

printf "Usage: /usr/local/mysql/mysql {start|stop|restart|kill}\n"

fi

赋予MySQL数据库的shell脚本可执行权限:chmod +x /usr/local/mysql/mysql

启动MySQL:/usr/local/mysql/mysql start

通过命令行登录管理MySQL服务器(提示输入密码时直接回车):/usr/local/mysql/bin/mysql -u root -p -S /tmp/mysql.sock

输入以下SQL语句,创建一个具有root权限的用户(root)和密码(123456):GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY '123456';GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' IDENTIFIED BY '123456';

停止MySQL命令:/usr/local/mysql/mysql stop

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值