当前linux系统CentOS release 6.5 (Final),由于系统迁移重新安装mysql5.7。
1.去官网下载对应的mysql软件
2.安装前检查是否安装了mysql
rpm -qa | grep mysql
3. 卸载之前安装的mysql
rpm -e 第二步骤中列出来的文件名 // 普通删除模式 ,可能会提示有相关依赖,可使用下面的命令
rpm -e --nodeps 第二步骤中列出来的文件名 // 强力删除模式
4. 将下载好的mysql上传到指定目录,如 /data
tar -zxvf mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz
5.重命名
mv mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz mysql-5.7.27
6.检查mysql组和用户是否存在,如无创建
cat /etc/group | grep mysql
#类似
mysql:x:500:
cat /etc/passwd | grep mysql
#类似
mysql:x:498:500::/home/mysql:/bin/bash
7.上面是存在的情况,如果不存在,执行添加命令:
groupadd mysql
useradd -r -g mysql mysql
#useradd -r参数表示mysql用户是系统用户,不可用于登录系统
8.创建data目录
cd mysql-5.7.27
mkdir data
9.将/data/mysql-5.7.27的所有者及所属组改为mysql
chown -R mysql.mysql /opt/mysql/mysql-5.7.27
10.在/data/mysql-5.7.27/support-files目录下创建my.cnf
# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# You can copy this file to
# /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is /usr/local/mysql/data) or
# ~/.my.cnf to set user-specific options.
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.
# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /tmp/my.sock
#default-character-set = gb2312
# Here follows entries for some specific programs
#user=zabbix_monitor
#password=monzab321
[mysqld_safe]
open-file-handles=8192
# The MySQL server
[mysqld]
#directory
datadir=/data/mysql-5.7.27/data
#basedir=/data/mysql/install
log-error=/data/mysql-5.7.27/log/mysqld.err
slow_query_log_file =/data/mysql-5.7.27/log/slow-query.log
log-bin=/data/mysql-5.7.27/binlog/mysql-bin
relay-log=/data/mysql-5.7.27/binlog/mysql-relay
#secure_file_priv=/data/mysql/temp
tmpdir=/data/mysql-5.7.27/tmp
#undo segment
innodb_max_undo_log_size=1073741824
innodb_undo_directory=/data/mysql-5.7.27/data
innodb_undo_log_truncate=OFF
innodb_undo_logs=128
innodb_undo_tablespaces=3
#character set
character-set-server = utf8
collation-server = utf8_bin
skip-character-set-client-handshake
#connection set
port = 3306
socket = /tmp/my.sock
skip-external-locking
skip-name-resolve
#multi processes replication
log_slave_updates
gtid_mode=ON
enforce_gtid_consistency=ON
slave_preserve_commit_order=1
master_info_repository=TABLE
slave_parallel_workers=8
slave_parallel_type=LOGICAL_CLOCK
relay_log_info_repository=TABLE
relay_log_recovery=ON
lower_case_table_names=1
#replication set
expire-logs-days = 15
open_files_limit = 65535
event_scheduler = OFF
server-id=462401
#slave-skip-errors=1046,1051,1062,1452,1064,1146,1452
#slave-skip-errors=1046,1051,1062,1452,1032,1451,1064
binlog_format=ROW
skip-slave-start
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
#system configuration
log_timestamps=system
log_error_verbosity=2
#read_only
innodb_file_per_table
default-storage-engine=INNODB
max_allowed_packet = 256m
net_buffer_length = 8K
max_binlog_size=512M
log_bin_trust_function_creators = 1
max_connections=1000
max_connect_errors=100
#query_cache_size=40M
slow-query-log
interactive_timeout=1800
wait_timeout=300
net_read_timeout=900
net_write_timeout=900
innodb_lock_wait_timeout = 500
long_query_time=600
connect_timeout=20
table_open_cache = 512
table_definition_cache = 512
group_concat_max_len =999999
#innodb
transaction_isolation = READ-COMMITTED
#innodb_print_all_deadlocks
read_buffer_size = 8M
read_rnd_buffer_size = 16M
sort_buffer_size = 8M
join_buffer_size = 16M
thread_cache_size = 64
#myisam
myisam_sort_buffer_size = 4M
key_buffer_size = 256M
#innodb set
innodb_data_home_dir = /data/mysql-5.7.27/data
innodb_buffer_pool_size = 12G
innodb_log_file_size = 1G
innodb_log_buffer_size = 16M
innodb_flush_method = O_DIRECT
innodb_stats_persistent_sample_pages = 64
innodb_write_io_threads=4
innodb_read_io_threads=4
#innodb_buffer_pool_dump_at_shutdown=1
#innodb_buffer_pool_load_at_startup=1
innodb_change_buffer_max_size=35
innodb_io_capacity=2000
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
11.拷贝,如果提示是否覆盖
cp support-files/my.cnf /etc/my.cnf
12.初始化 mysqld
./bin/mysqld --initialize --user=mysql --basedir=/data/mysql-5.7.27/ --datadir=/data/mysql-5.7.27/data/
13.初始化完成之后,查看日志,最后一行的临时密码,日志文件路径和名字不一定一样,仔细找找
/data/mysql-5.7.27/log/mysqld.err
14.如果启动失败看提示内容可能是权限问题,执行类似如下命令,给文件夹授权
chown -R mysql.mysql /opt/mysql/mysql-5.7.27
15.把启动脚本放到开机初始化目录,并且把mysql.server文件中的路径修改正确即可
cp support-files/mysql.server /etc/init.d/mysql
16.启动mysql服务
service mysql start
17.登录mysql,密码为上述初始密码
./bin/mysql -u root -p
18.修改密码,登录进去以后分别执行以下命令
set password=password('123456');
grant all privileges on *.* to root@'%' identified by '123456';
flush privileges;
19.添加远程访问权限
mysql> use mysql;
mysql> update user set host='%' where user = 'root';
mysql> flush privileges;
20.重启mysql生效
service mysql stop
service mysql start
或
service mysql restart
21.本地远程连接时,需要设置服务器的防火墙,允许3306端口访问
iptables -I INPUT -p tcp --dport 3690 -j ACCEPT
保存
/etc/rc.d/init.d/iptables save
重启
service iptables restart
查看
/etc/init.d/iptables status