点击(此处)折叠或打开
- groupadd mysql
- useradd -g mysql mysql
解压mysql文件&0编译源代码
点击(此处)折叠或打开
- tar zxvf mysql-5.1.65.tar.gz
- cd mysql-5.1.65
- ./configure --prefix=/usr/local/mysql/ --with-server-suffix=-zsd-edition --enable-assembler --enable-local-infile --enable-thread-safe-client --with-big-tables --with-charset=utf8 --with-extra-charsets=gbk,gb2312,utf8,ascii --with-readline --with-ssl --with-embedded-server --with-pthread --with-mysqld-user=mysql --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static --with-plugins=partition,innobase,innodb_plugin > /root/mysql_setuplogs_configure.log 2>&1
查看/root/mysql_setuplogs_configure.log,如果出现libtool的问题,按下述方法可解决
查看libtool是否已经安装。
1、确认libtool是否已经安装,如果没有安装的话,则先安装libtool
点击(此处)折叠或打开
- # rpm -qa | grep libtool
- # yum -y install libtool
点击(此处)折叠或打开
- # autoreconf --force --install
- # libtoolize --automake --force
- # automake --force --add-missing
make&安装:
点击(此处)折叠或打开
- make > /root/mysql_setuplogs_make.log 2>&1
- make install > /root/mysql_setuplogs_makeinstall.log 2>&1
修改相关路径权限:
点击(此处)折叠或打开
- cd /usr/local/
-
- chown -R mysql:mysql mysql
-
- mkdir -p /data/mysqldata/3306
- cd /data/mysqldata/3306
- mkdir data binlog tmp innodb_ts innodb_log
- chown -R mysql:mysql ./
点击(此处)折叠或打开
- /usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldata/3306/data
配置my.cnf
点击(此处)折叠或打开
- vi /data/mysqldata/3306/my.cnf
-
- [client]
- port = 3306
- socket = /data/mysqldata/3306/mysql.sock
- character-set-server = utf8
- # Here follows entries for some specific programs
- # The MySQL server
- [mysqld]
- port = 3306
- user = mysql
- socket = /data/mysqldata/3306/mysql.sock
- pid-file = /data/mysqldata/3306/mysql.pid
- basedir = /usr/local/mysql
- datadir = /data/mysqldata/3306/data
- tmpdir = /data/mysqldata/3306/tmp
- open_files_limit = 10240
- server-id = 1333306
- lower_case_table_names = 1
- character-set-server = utf8
- skip-name-resolve
- max_connections = 3000
- max_connect_errors = 6000
- max_allowed_packet = 512M
- max_heap_table_size = 1024M
- max_length_for_sort_data = 4096
- back_log=100
- interactive_timeout = 600
- wait_timeout = 600
- default-storage-engine = InnoDB
- net_buffer_length = 8K
- sort_buffer_size = 2M
- join_buffer_size = 4M
- read_buffer_size = 2M
- read_rnd_buffer_size = 16M
- query_cache_size = 128M
- query_cache_limit = 2M
- query_cache_min_res_unit = 2k
- thread_cache_size = 300
- table_open_cache = 1024
- tmp_table_size = 256M
- #*********** Logs related settings ***********
- log-bin = /data/mysqldata/3306/binlog/mysql-bin
- log-slave-updates =1
- binlog_format=statement
- binlog_cache_size=32m
- max_binlog_cache_size=512m
- max_binlog_size=512m
- long_query_time = 3
- log_output = FILE
- log-error = /data/mysqldata/3306/mysql-error.log
- slow_query_log = 1
- slow_query_log_file = /data/mysqldata/3306/slow_statement.log
- log_queries_not_using_indexes
- general_log = 0
- general_log_file = /data/mysqldata/3306/general_statement.log
- expire-logs-days = 14
- #*********** MyISAM Specific options ***********
- key_buffer_size = 32M
- bulk_insert_buffer_size = 64M
- myisam_sort_buffer_size = 128M
- myisam_max_sort_file_size = 10G
- myisam_repair_threads = 1
- myisam_recover
- #*********** INNODB Specific options ***********
- innodb_file_per_table
- transaction-isolation = READ-COMMITTED
- innodb_additional_mem_pool_size = 16M
- innodb_buffer_pool_size = 1024M
- innodb_data_home_dir = /data/mysqldata/3306/innodb_ts
- innodb_data_file_path = ibdata1:2048M:autoextend
- innodb_file_io_threads = 4
- innodb_thread_concurrency = 0
- innodb_log_buffer_size = 16M
- innodb_log_file_size = 256M
- innodb_log_files_in_group = 2
- innodb_log_group_home_dir = /data/mysqldata/3306/innodb_log
- innodb_flush_log_at_trx_commit = 2
- innodb_max_dirty_pages_pct = 80
- innodb_lock_wait_timeout = 120
- innodb_flush_method=O_DIRECT
- [mysqldump]
- quick
- max_allowed_packet = 512M
- [mysql]
- no-auto-rehash
- # Remove the next comment character if you are not familiar with SQL
- #safe-updates
- [myisamchk]
- key_buffer_size = 32M
- sort_buffer_size = 20M
- read_buffer_size = 2M
- write_buffer_size = 2M
- [mysqlhotcopy]
- interactive-timeout
- [mysqld_safe]
- open-files-limit = 8192
启动mysql服务:
点击(此处)折叠或打开
- /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysqldata/3306/my.cnf &
进入mysql:
点击(此处)折叠或打开
- /usr/local/mysql/bin/mysql -uroot -S /data/mysqldata/3306/mysql.sock
关闭mysql:
点击(此处)折叠或打开
- /usr/local/mysql/bin/mysqladmin -uroot -S /data/mysqldata/3306/mysql.sock shutdown
安装mysql后,对安全性做一点设置:
(1)删除掉不安全的用户:
点击(此处)折叠或打开
- drop user ''@'localhost';
- drop user ''@'mysql-n1';
(2)为root用户设置密码:(以root用户登录)
点击(此处)折叠或打开
- set password=password('zsd0507');
设置环境变量:
点击(此处)折叠或打开
- sudo su - mysql
- vi /home/mysql/.bash_profile
- umask 022
- MYSQL_BASE=/usr/local/mysql
- MYSQL_HOME=/usr/local/mysql
- PATH=$MYSQL_BASE/bin:$PATH
- export PATH
- export MYSQL_BASE MYSQL_HOME
- 使得环境变量生效:
- source /home/mysql/.bash_profile
设置启动脚本(让它跟系统一起自动启动)
点击(此处)折叠或打开
- cd /etc/init.d
- vi mysql
#!/bin/sh
mysql_port=3306
mysql_username="root"
mysql_password="zsd0507"
function_start_mysql()
{
printf "Starting MySQL...\n"
/bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysqldata/
${mysql_port}/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
/data/mysqldata/${mysql_port}/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: /data/mysqldata/${mysql_port}/mysql {start|stop|restart|
kill}\n"
fi
- chmod 755 mysql
到此,全部结束!~