安装mysql之前要remove掉系统自带的mysql:
rpm -qa | grep "MySQL*" 和rpm -qa | grep mysql 要确保卸载干净
rpm -e MySQL-server-5.1.74-1.el6.x86_64.rpm --nodeps
mysql这里使用rpm 安装:
安装包:MySQL-5.6.26-1.linux_glibc2.5.x86_64.rpm-bundle.tar
tar xf MySQL-5.6.26-1.linux_glibc2.5.x86_64.rpm-bundle.tar
解压出:
[[email protected] mysql_install_packet]# ll
total 619196
-rw-r--r-- 1 root root 317030400 Aug 20 11:55 MySQL-5.6.26-1.linux_glibc2.5.x86_64.rpm-bundle.tar
-rw-r--r-- 1 7155 wheel 23142383 Jul 16 01:16 MySQL-client-5.6.26-1.linux_glibc2.5.x86_64.rpm
-rw-r--r-- 1 7155 wheel 4586909 Jul 16 01:16 MySQL-devel-5.6.26-1.linux_glibc2.5.x86_64.rpm
-rw-r--r-- 1 7155 wheel 117649695 Jul 16 01:17 MySQL-embedded-5.6.26-1.linux_glibc2.5.x86_64.rpm
-rw-r--r-- 1 7155 wheel 88754725 Jul 16 01:17 MySQL-server-5.6.26-1.linux_glibc2.5.x86_64.rpm
-rw-r--r-- 1 7155 wheel 2418592 Jul 16 01:18 MySQL-shared-5.6.26-1.linux_glibc2.5.x86_64.rpm
-rw-r--r-- 1 7155 wheel 5181237 Jul 16 01:18 MySQL-shared-compat-5.6.26-1.linux_glibc2.5.x86_64.rpm
-rw-r--r-- 1 7155 wheel 75283535 Jul 16 01:18 MySQL-test-5.6.26-1.linux_glibc2.5.x86_64.rpm
先创建用户:
groupadd mysql --创建mysql用户组
useradd -M -s /sbin/nologin mysql -g mysql --这里创建的mysql不能登录没有家目录
rpm逐一安装:
rpm -ivh MySQL-client-5.6.26-1.linux_glibc2.5.x86_64.rpm
rpm -ivh MySQL-devel-5.6.26-1.linux_glibc2.5.x86_64.rpm
rpm -ivh MySQL-embedded-5.6.26-1.linux_glibc2.5.x86_64.rpm
rpm -ivh MySQL-shared-5.6.26-1.linux_glibc2.5.x86_64.rpm
rpm -ivh MySQL-shared-compat-5.6.26-1.linux_glibc2.5.x86_64.rpm
rpm -ivh MySQL-server-5.6.26-1.linux_glibc2.5.x86_64.rpm
这里test不用安装了!
更改数据目录:
mkdir /mysqldata
将rpm默认安装的数据目录下的文件都移动到新目录下面:
mkdir -p /mysqldata/
mv /var/lib/mysql/* /mysqldata/
cd /mysqldata
mkdir slowlog
mkdir binlog
mkdir relaylog
mkdir tmpdata
mkdir general_log
chown -R mysql:mysql /mysqldata
更改my.cnf文件:
使用下列内容替换原有/etc/my.cnf内容,具体参数要根据应用需求和服务器情况进行调整:
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
#使用本配置之前请在数据目录新建一下目录: tmpdata binlog relaylog general_log slowlog ,并且赋予mysql用户权限!
[mysqld]
port=3306
datadir=/mysqldata/
tmpdir=/mysqldata/tmpdata
socket=/mysqldata/mysql.sock
skip_external_locking
open_files_limit = 65535
lower_case_table_names = 1
#### skip domain hostname ###########
skip-name-resolve
#### bin-log ########################
server-id=1
log-bin=/mysqldata/binlog/mysql-bin.index
max_binlog_size=128M
binlog-format=row
sync_binlog=1
#binlog-ignore-db=mysql
#replicate-ignore-db=mysql
#master-connect-retry=60
#### relay log ######################
#relay_log = /mysqldata/relaylog/mysql-relay
#relay_log_purge = 1
#expire_logs_days=3
#skip_slave_start
#### character ######################
character-set-server=utf8
#init_connect=‘SET NAMES utf8‘
#### connect ########################
max_connections=1024
max_allowed_packet=16M
#### timeout ########################
wait_timeout=1024
interactive_timeout=1024
#### vaiables size ##################
tmp_table_size=64M
max_heap_table_size = 64M
key_buffer_size=128M
table_definition_cache=1024
table_open_cache=1024
join_buffer_size=4M
sort_buffer_size=4M
read_buffer_size=8M
myisam_sort_buffer_size = 64M
thread_cache_size = 16
thread_concurrency = 32
explicit_defaults_for_timestamp = 1
sysdate-is-now
########## general_log ############
#general_log=ON
#general_log_file=/mysqldata/general_log/general_log.log
############# slow_log ############
#default OFF
long_query_time=3
slow_query_log=1
slow_query_log_file=/mysqldata/slowlog/slow-query.log
log_queries_not_using_indexes=1
########## query_cache ############
#default OFF
#explicit_defaults_for_timestamp=true
query_cache_type=0
query_cache_size=0
#thread_cache = 500
#query_cache_limit=2M
########### innodb ################
innodb_read_io_threads = 8
innodb_write_io_threads = 8
innodb_buffer_pool_instances = 8
innodb_buffer_pool_size = 2G
innodb_additional_mem_pool_size =32M
innodb_thread_concurrency = 32
innodb_file_per_table=1
innodb_data_home_dir=/mysqldata
innodb_data_file_path=ibdata1:12M:autoextend
innodb_io_capacity = 2000
innodb_autoinc_lock_mode = 2
innodb_locks_unsafe_for_binlog = 1
transaction-isolation = READ-COMMITTED
innodb_log_file_size = 128M
innodb_log_buffer_size = 32M
innodb_log_files_in_group = 3
innodb_lock_wait_timeout=60
innodb_flush_method=O_DIRECT
innodb_purge_threads=1
innodb_support_xa=1
innodb_flush_log_at_trx_commit = 1
[client]
default-character-set=utf8
[mysql]
socket=/mysqldata/mysql.sock
no_auto_rehash
prompt = "\\R:\\m:\\s \\d> "
[mysqldump]
socket=/mysqldata/mysql.sock
添加mysql服务到开机启动:
chkconfig --add mysql
chkconfig --levels 235 mysql on
最后vi /etc/init.d/mysql 修改basedir和datadir为下面内容:
basedir=/usr
datadir=/mysqldata
service mysql start
cat /root/.mysql_secret
mysql -uroot -p‘5P19xzxfIPUWyxwR‘ --这个密码为mysql_secret里面的
SET PASSWORD = PASSWORD(‘mysteel‘);
flush privileges;
drop database test;