標籤:二進位 mysql 作業系統
作業系統版本:
[[email protected] ~]# cat /etc/redhat-release
CentOS release 6.5 (Final)
作業系統核心:
[[email protected] ~]# uname -r
2.6.32-431.el6.x86_64
關閉防火牆並關閉自啟動:
[[email protected] ~]# /etc/init.d/iptables stop
[[email protected] ~]# chkconfig --level 2345 iptables off
臨時禁用selinux,並修改設定檔重啟系統也禁用:
[[email protected] ~]# setenforce 0
[[email protected] ~]# vim /etc/sysconfig/selinux
SELINUX=disabled
建立目錄,把mysql二進位包上傳到此目錄下:
[[email protected] ~]# mkdir -p /home/tools
切換到目錄下,解壓二進位包:
[[email protected] ~]# cd /home/tools/
[[email protected] tools]# tar zxf mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz
建立解壓包的軟連結,建立軟串連的目的主要是方便以後升級:
[[email protected] tools]# ln -s /home/tools/mysql-5.7.14-linux-glibc2.5-x86_64 /usr/local/mysql
建立使用者組和使用者:
[[email protected] local]# groupadd mysql
[[email protected] local]# useradd -M -g mysql -s /sbin/nologin -d /usr/local/mysql/ mysql
建立mysql資料,日誌,臨時等目錄,並修改所有者和所屬組:
[[email protected] local]# mkdir -p /data/mysql/mysql3306/data /data/mysql/mysql3306/log /data/mysql/mysql3306/tmp
[[email protected] local]# chown -R mysql:mysql /data/mysql/mysql3306/
修改/etc/my.cnf檔案,使用預設my.cnf的也可以初始化成功,不過一些檔案的位置會有點亂,這雷根據個人習慣修改如下:
[[email protected] tools]# vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysql]
prompt="\\[email protected]\\h [\\d]>"
#pager="less -i -n -S"
#tee=/opt/mysql/query.log
no-auto-rehash
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
log = /opt/mysql/mysqld_multi.log
[mysqld]
#misc
user = mysql
basedir = /usr/local/mysql
datadir = /data/mysql/mysql3306/data
port = 3306
socket = /tmp/mysql.sock
event_scheduler = 0
tmpdir = /data/mysql/mysql3306/tmp
#timeout
interactive_timeout = 300
wait_timeout = 300
#character set
character-set-server = utf8
open_files_limit = 65535
max_connections = 100
max_connect_errors = 100000
#lower_case_table_names =1
#logs
log-output=file
slow_query_log = 1
slow_query_log_file = slow.log
log-error = error.log
log_warnings = 2
pid-file = mysql.pid
long_query_time = 1
#log-slow-admin-statements = 1
#log-queries-not-using-indexes = 1
log-slow-slave-statements = 1
#binlog
#binlog_format = STATEMENT
binlog_format = row
server-id = 23306
log-bin = /data/mysql/mysql3306/logs/mysql-bin
binlog_cache_size = 4M
max_binlog_size = 256M
max_binlog_cache_size = 1M
sync_binlog = 0
expire_logs_days = 10
#procedure
log_bin_trust_function_creators=1
#
gtid-mode = 0
#relay log
skip_slave_start = 1
max_relay_log_size = 128M
relay_log_purge = 1
relay_log_recovery = 1
relay-log=relay-bin
relay-log-index=relay-bin.index
log_slave_updates
#slave-skip-errors=1032,1053,1062
#skip-grant-tables
#buffers & cache
table_open_cache = 2048
table_definition_cache = 2048
table_open_cache = 2048
max_heap_table_size = 96M
sort_buffer_size = 128K
join_buffer_size = 128K
thread_cache_size = 200
query_cache_size = 0
query_cache_type = 0
query_cache_limit = 256K
query_cache_min_res_unit = 512
thread_stack = 192K
tmp_table_size = 96M
key_buffer_size = 8M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 32M
#myisam
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
#innodb
innodb_buffer_pool_size = 100M
innodb_buffer_pool_instances = 1
innodb_data_file_path = ibdata1:100M:autoextend
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 8M
innodb_log_file_size = 100M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 50
innodb_file_per_table = 1
innodb_rollback_on_timeout
innodb_status_file = 1
innodb_io_capacity = 2000
transaction_isolation = READ-COMMITTED
innodb_flush_method = O_DIRECT
資料庫初始化,預設是帶密碼的,也可以指定參數--initialize-insecure則不要求輸入密碼
[[email protected] data]# cd /usr/local/mysql/bin/
[[email protected] bin]# ./mysqld --initialize --user=mysql
查看密碼:
[[email protected] data]# cat /data/mysql/mysql3306/data/error.log |grep password
2016-11-17T13:29:25.055578Z 1 [Note] A temporary password is generated for [email protected]: XgqTE9Cb+rLc
複製啟動指令碼並改名為mysql:
[[email protected] init.d]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
啟動mysql服務,並加入自啟動中:
[[email protected] init.d]# /etc/init.d/mysql start
[[email protected] ~]# chkconfig --add mysql
執行命令加入環境變數:
echo ‘export PATH=$PATH:/usr/local/mysql/bin/‘>>/etc/profile
[[email protected] init.d]# source /etc/profile
[[email protected] init.d]# mysql -S /tmp/mysql.sock -p
Enter password: --寫入上面查看到的密碼
立即修改使用者密碼:
unknown)@localhost [(none)]>alter user user() identified by ‘147258‘;
查看資料庫帳號,5.7中user表中帳號比較安全,不需要帳號安全強化,即不需要刪除無用帳號
[email protected] [(none)]>select user,host from mysql.user;
+-----------+-----------+
| user | host |
+-----------+-----------+
| mysql.sys | localhost |
| root | localhost |
+-----------+-----------+
本文出自 “10979687” 部落格,請務必保留此出處http://10989687.blog.51cto.com/10979687/1873968
mysql 5.7.14二進位包安裝