二进制安装mysql详解

下载文件

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz 

官网地址下载所需版本

建立mysql用户

 groupadd mysql
 useradd -g mysql mysql -s /sbin/nologin

解压文件并赋权限

tar zxf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz 

# 移动到/usr/local/mysql
mv mysql-5.7.26-linux-glibc2.12-x86_64 /usr/local/mysql

# 切换到目录
cd /usr/local/mysql

chown mysql:mysql -R mysql

建立数据目录

mkdir -p  /data/mysql/

chown -R mysql:mysql /data/mysql/

编辑配置文件


  [mysql]
  no-auto-rehash

  [mysqld]
  #Misc
  ft_min_word_len=1
  event_scheduler = 1
  max_allowed_packet = 120M

  #Performance
  log-bin=mysql-bin
  net_read_timeout = 1800
  wait_timeout = 1800
  interactive_timeout = 1800
  open_files_limit = 10240
  back_log = 150binlog_cache_size
  max_connections = 1000
  max_connect_errors = 50
  external-locking = FALSE
  performance_schema = 0

  #buffers & cache
  table_open_cache = 2048   #在mysql5.6不再支持table_cache
  table_definition_cache = 2048
  max_heap_table_size = 246M
  tmp_table_size = 246M
  sort_buffer_size = 58M
  join_buffer_size = 58M
  thread_cache_size = 256
  #thread_concurrency = 8
  query_cache_type = 1
  query_cache_size = 332M
  query_cache_limit = 200M
  query_cache_min_res_unit = 2k
  thread_stack = 192K
  read_buffer_size = 10M
  read_rnd_buffer_size = 16M
  bulk_insert_buffer_size = 64M

  #logs
  #log-output=file
  log-error=/usr/local/mysql/logs/mysql.err
  log_warnings = 2
  slow-query-log
  slow-query-log-file=/usr/local/mysql/logs/slow-log.log
  long_query_time = 1
  #log-queries-not-using-indexes = 1
  log-slow-admin-statements = 1
  log-slow-slave-statements = 1

  #binlog & replication
  server-id = 161276398
  binlog-row-image = minimal
  #binlog_format = MIXED
  binlog_format = ROW
  #log-bin = /data/mysql-3306/binlog/mysql-bin
  binlog_cache_size = 40M
  max_binlog_cache_size = 2G
  max_binlog_size = 1G
  expire_logs_days = 7
  relay-log-purge = 1
  sync_binlog = 0
  skip-slave-start = 1
  log-slave-updates  = 1

  #Myisam engine
  key_buffer_size = 1420M
  myisam_sort_buffer_size = 128M
  myisam_max_sort_file_size = 1G
  myisam_repair_threads = 1
  myisam_recover
  lower_case_table_names = 0
  skip-name-resolve
  slave-skip-errors = 1032,1062
 log_bin_trust_function_creators = 1

  #Innodb engine
  innodb_additional_mem_pool_size = 660M
  innodb_buffer_pool_size = 20G
  innodb_data_file_path = ibdata1:100M:autoextend
  innodb_file_per_table = 1
  innodb_thread_concurrency = 0
  innodb_flush_log_at_trx_commit = 1
  innodb_log_buffer_size = 16M
  innodb_log_file_size = 1024M
  innodb_log_files_in_group = 3
  innodb_max_dirty_pages_pct = 75
  innodb_lock_wait_timeout = 120
  innodb_rollback_on_timeout
  innodb_status_file = 1
  innodb_io_capacity = 2000
  transaction_isolation = READ-COMMITTED
  innodb_flush_method = O_DIRECT
  innodb-support-xa = 0
  innodb_read_io_threads = 8
  innodb_write_io_threads = 8
  innodb_file_format = Barracuda


  group_concat_max_len =  -1

  #replication
 # auto_increment_increment=2
 # auto_increment_offset=1
  [mysqldump]
  quick
  max_allowed_packet = 32M  


启动数据库

cd /usr/local/mysql/bin

./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql --initialize

./mysqld_safe --defaults-file=/etc/my.cnf &

登录数据库

# 查看数据库临时
cat /data/mysql/error.log | grep password

./mysql -u root -p

重置数据库密码

SET PASSWORD = 'root123';   #更改密码

ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;    #永不过期

flush privileges;           #刷新权限

关闭数据库

cd /usr/local/mysql/bin/

./mysqladmin -uroot -proot123 shutdown

为了方便起见,将Mysql加入环境变量

vim /etc/profile
PATH="$PATH":/usr/local/mysql/bin       #加入
source /etc/profile

sys-v方式管理mysql

cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld

# 查看mysql状态
 /etc/init.d/mysqld status/stop/start/restart


#查看参数是否生效
show global variables like '%binlog_cache%';

你可能感兴趣的:(二进制安装mysql详解)