安装MySQL之最佳实践-亲试ok(最原始版本)

 

mysql必须装在系统最大分区,此文档以最大分区为 /data 为例

1.检查安装环境

[root@baiwang ~]# rpm -qa |grep mysql
[root@baiwang ~]# yum remove mysql mysql-server mysql-libs
[root@baiwang ~]# rpm -e mysql-libs-5.1.71-1.el6.x86_64 --nodeps
 

2.添加用户和组:

[root@baiwang ~]#groupadd mysql
[root@baiwang ~]#useradd -g mysql mysql
 

3.创建目录及授权

[root@baiwang ~]# mkdir -pv /data/mysql/data 
[root@baiwang ~]# mkdir -pv /data/mysql/log/iblog
[root@baiwang ~]# mkdir -pv /data/mysql/log/binlog
[root@baiwang ~]# mkdir -pv /data/mysql/log/relaylog
[root@baiwang ~]# mkdir -pv /data/mysql/run
[root@baiwang ~]# mkdir -pv /data/mysql/tmp
[root@baiwang ~]# chown -R mysql:mysql /data/mysql
[root@baiwang ~]# chmod -R 755 /data/mysql
 

4.上传并解压mysql安装包

1.上传mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz/opt
2.进入opt目录
[root@baiwang ~]#cd /opt
3.解压mysql安装包
[root@baiwang ~]# tar zxf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz
4.进入mysql目录
[root@baiwang ~]#cd mysql-5.6.30-linux-glibc2.5-x86_64
5.拷贝文件到/data/mysql/
[root@baiwang ~]#cp -R * /data/mysql/
6.更改目录权限
[root@baiwang ~]# chown -R mysql:mysql /data/mysql
 

5.修改配置文件my.cnf参数

1.拷贝my.cnf文件到/data/mysql目录下
[root@baiwang~]# cp /data/mysql/support-files/my-default.cnf  /data/mysql/my.cnf
2.打开my.cnf文件
[root@baiwang ~]# vi  /data/mysql/my.cnf
3.删除my.cnf文件里的内容,添加以下信息。注意查看路径
# For advice on how to change settings please see
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
 
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
 
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
 
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
 
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
 
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[client]
port = 3306
socket =/data/mysql/run/mysql.sock
default-character-set=gbk
 
[mysql]
no-auto-rehash
 
[mysqld]
## enable autocommit
autocommit=1
general_log=off
explicit_defaults_for_timestamp=true
character_set_server = gbk
auto_increment_increment= 2
auto_increment_offset   = 1
lower_case_table_names=1
 
# system
basedir=/data/mysql
datadir=/data/mysql/data/
max_allowed_packet=134217728
max_connections=8192
max_user_connections=8000
open_files_limit=65535
pid_file=/data/mysql/run/mysqld.pid
port=3306
server_id=128
skip_name_resolve=ON
socket=/data/mysql/run/mysql.sock
tmpdir=/data/mysql/tmp
 
# binlog
binlog_cache_size=32768
binlog_format=row
expire_logs_days=15
log-bin=/data/mysql/log/binlog/master-bin
log-bin-index=/data/mysql/log/binlog/master-bin.index
log_slave_updates=ON
max_binlog_cache_size=2147483648
max_binlog_size=524288000
sync_binlog=100
 
#relay
 
# LOGGING #
log_error                      = /data/mysql/log/alert.log
log_queries_not_using_indexes  = 1
slow_query_log                = 1
slow_query_log_file            = /data/mysql/log/slow.log
log_slave_updates=ON
log_slow_admin_statements=1
long_query_time=1
 
#slave#
slave_skip_errors=OFF
log_slave_updates=ON
 
# innodb #
innodb_log_group_home_dir=/data/mysql/log/iblog
innodb_data_home_dir=/data/mysql/log/iblog
innodb_adaptive_flushing=1
innodb_additional_mem_pool_size=20M
innodb_buffer_pool_instances=8
innodb_change_buffering=inserts
innodb_data_file_path=ibdata1:32M;ibdata2:16M:autoextend
innodb_flush_method            = O_DIRECT
innodb_log_files_in_group      = 4
innodb_log_file_size          = 100M
innodb_flush_log_at_trx_commit = 1
innodb_file_per_table          = 1
innodb_buffer_pool_size        = 128M
innodb_file_format=Barracuda
innodb_file_io_threads=4
innodb_flush_neighbors=0
innodb_io_capacity=200
innodb_lock_wait_timeout=5
innodb_log_buffer_size=64M
innodb_lru_scan_depth=2048
innodb_max_dirty_pages_pct=60
innodb_old_blocks_time=1000
innodb_online_alter_log_max_size=200M
innodb_open_files=200
innodb_print_all_deadlocks=1
innodb_purge_threads=4
innodb_read_ahead_threshold=0
innodb_read_io_threads=8
innodb_rollback_on_timeout=0
innodb_sort_buffer_size=2M
innodb_spin_wait_delay=6
innodb_stats_on_metadata=0
innodb_strict_mode=1
innodb_sync_array_size=256
innodb_sync_spin_loops=30
innodb_thread_concurrency=64
innodb_use_native_aio=0
innodb_write_io_threads=8
innodb_support_xa=1
 
[mysqld_safe]
datadir=/data/mysql/data/
 
 

6.执行安装脚本

1.进入/data/mysql目录
# cd /data/mysql/
 
2.执行安装脚本
[root@baiwang~]# ./scripts/mysql_install_db  --defaults-file=/data/mysql/my.cnf  --user=mysql --datadir=/data/mysql/data
 
 

7.修改系统环境变量

1.打开/etc/profile文件,加入标红内容
[root@baiwang ~]# vi /etc/profile
 
PATH=/data/mysql/bin:$PATH:/sbin
 
2.刷新文件
[root@baiwang ~]# source /etc/profile
 
 

8.自启动脚本

1.拷贝my.cnf文档
[root@baiwang ~]# cp /data/mysql/my.cnf /etc/my.cnf
 
2.打开mysql文件,在mysqld_pid_file_path=后添加标红信息
[root@baiwang ~]#vi /etc/init.d/mysql
 
mysqld_pid_file_path=/data/mysql/run/mysqld.pid
 
3.启动mysql脚本
[root@baiwang]# chkconfig --add mysql
[root@baiwang]# /etc/init.d/mysql stop
 
4.上传mysql数据库备份文件
skdata_1116.sql/opt
 

9.删除默认匿名账户及导入数据库

1.登录Mysql
[root@baiwang]#mysql -h127.0.0.1 -uroot -P3306
 
2.导入数据库
mysql> DELETE FROM mysql.user WHERE User='';
mysql>use skdata
mysql>create user 'sk'@'%' identified by 'password';
mysql>GRANT ALL PRIVILEGES ON skdata.* TO 'sk'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
 
 
创建时间:2021-12-22 12:03
浏览量:0