msyql 5.7安裝

===============================================================Mysql5.7安裝===============================================================
mysql官網下載mysql-5.7.25-el7-x86_64.tar.gz
[root@centos7 src]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.25-el7-x86_64.tar.gz
一、卸載系統自帶的Mariadb
rpm -qa |grep mysql | xargs -i rpm -e --nodeps {}
二、刪除/etc下my.cnf配置文件(如果存在的話)、檢查mysql是否存在
rm -rf /etc/my.cnf
rpm -qa | grep mysql
三、檢查mysq  src]# cat /etc/passwd | grep mysql
[root@centos7 src]# groupadd mysql
[root@centos7 src]# useradd -g mysql mysql
四、解壓mysql-5.7.25-el7-x86_64.tar.gz,移動到/usr/local/mysql5.7下,更改文件歸屬爲mysql
    tar -zxvf mysql-5.7.25-el7-x86_64.tar.gz
	groupadd mysql
	useradd -g mysql mysql
	mkdir -p /usr/local/mysql5.7/
	mv * /usr/local/mysql5.7/
	mkdir /usr/local/mysql5.7/data
	mkdir /usr/local/mysql5.7/log
	touch /usr/local/mysql5.7/log/mysqld.log
	chown -R mysql /usr/local/mysql5.7/
	chgrp -R mysql /usr/local/mysql5.7/
五、安裝
[root@centos7 mysql5.7]# /usr/local/mysql5.7/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql5.7/ --datadir=/usr/local/mysql5.7/data/
六、新建配置文件my.cnf,啓動
cp /etc/my.cnf /etc/my.cnfbak
vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8mb4

[mysqld]
skip_host_cache
skip-name-resolve=1
server-id = 1
port = 3306
log-bin=mysql-bin

socket = /tmp/mysql.sock
basedir=/usr/local/mysql5.7/
datadir=/usr/local/mysql5.7/data
user = mysql

init-connect = 'SET NAMES utf8'
character-set-server = utf8

back_log = 300

max_connections = 3000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 512
max_allowed_packet = 32M
binlog_cache_size = 4M
max_heap_table_size = 256M
tmp_table_size = 256M

read_buffer_size = 2M
read_rnd_buffer_size = 16M
sort_buffer_size = 4M
join_buffer_size = 4M
key_buffer_size = 1024M

thread_cache_size = 300

query_cache_type = 1
query_cache_size = 64M
query_cache_limit = 2M

ft_min_word_len = 4

binlog_format = mixed
expire_logs_days = 30
log_error=/usr/local/mysql5.7/master.err #放開啓動報錯
slow_query_log = 1
long_query_time = 1
slow_query_log_file =/usr/local/mysql5.7/data/slow.log
performance_schema = 0
explicit_defaults_for_timestamp

lower_case_table_names = 1
skip-external-locking

default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
[mysqld_safe]# 之前滅有待測試
log-error=/usr/local/mysql5.7/log/mysqld.log
chown 777 /etc/my.cnf 
===============================================================啓動數據庫修改密碼===============================================================
cp /usr/local/mysql5.7/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
#修改啓動配置文件
vim /etc/init.d/mysqld
basedir=/usr/local/mysql5.7/
datadir=/usr/local/mysql5.7/data

===============================================================添加環境變量===============================================================
vim /etc/profile
添加mysql環境變量
# MYSQL
export MYSQL_HOME="/usr/local/mysql5.7/"
export PATH="$PATH:$MYSQL_HOME/bin"
使環境變量生效
source /etc/profile

===============================================================重置root密碼===============================================================
service mysqld start --skip-grant-tables
use mysql;
update user set authentication_string=password("123456") where user="root";
grant all privileges on *.* to root@'%' identified by '123456' with grant option;
flush privileges;    
create user 'system'@'%' identified by '123456';
grant all privileges on *.* to system@'%' identified by '123456' with grant option; 
flush privileges;
#重啓數據庫密碼生效
service mysqld restart ;
set password=password('123456');
flush privileges;
===============================================================mysql 導入導出 備份===============================================================
mysqldump  aqzx           -usystem -p'XXX'  >    aqzx.sql        
create database aqzx;  
mysql  aqzx        -usystem -p'XXX'  <   aqzx.sql          
  


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章