1.解壓安裝包:
成都創(chuàng)新互聯(lián)公司專(zhuān)業(yè)為企業(yè)提供西湖網(wǎng)站建設(shè)、西湖做網(wǎng)站、西湖網(wǎng)站設(shè)計(jì)、西湖網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、西湖企業(yè)網(wǎng)站模板建站服務(wù),十余年西湖做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
tar -zxvf MySQL-5.7.23-linux-glibc2.12-x86_64.tar.gz
創(chuàng)建mysql目錄:
mkdir -p /data/mysql
cd /data/mysql/
binlog存儲(chǔ)目錄:
mkdir binlog
mysql數(shù)據(jù)目錄:
mkdir data
mysql日志目錄:
mkdir log
限制mysql導(dǎo)入導(dǎo)出目錄:
mkdir tmp
授權(quán)mysql用戶(hù):
chown -R mysql:mysql /data/mysql/
移動(dòng)目錄到自定義的位置,這里存放位置為/usr/local下:
mv mysql-5.7.23-linux-glibc2.12-x86_64 /usr/local/mysql
cd /usr/local/
程序目錄授權(quán):
chown -R mysql:mysql /usr/local/mysql/
備份自帶的配置文件:
cp my.cnf my.cnf.back
編輯新的配置文件:
vi my.cnf
將以下內(nèi)容替換源文件的內(nèi)容
[mysqld]
#bind-address 0.0.0.0
back_log = 2000
basedir = /usr/local/mysql
character-set-server = utf8mb4
datadir = /data/mysql/data
event_scheduler = ON
innodb_autoinc_lock_mode = 1
innodb_buffer_pool_size = 16G
innodb_data_file_path = ibdata1:500M:autoextend
innodb_data_home_dir = /data/mysql/data
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = O_DIRECT
innodb_io_capacity = 2000
innodb_log_buffer_size = 8388608
innodb_log_files_in_group = 3
innodb_log_group_home_dir = /data/mysql/data
innodb_max_dirty_pages_pct = 50
innodb_open_files = 1024
innodb_read_io_threads = 8
innodb_thread_concurrency = 20
innodb_write_io_threads = 8
innodb_lock_wait_timeout = 10
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
key_buffer_size = 3221225472
innodb_log_file_size = 1G
local_infile = 1
slave-skip-errors = 1062 1032
binlog-format = row
log-bin = /data/mysql/binlog/mysql-bin.log
expire_logs_days = 7
log_bin_trust_function_creators = 1
log_output = FILE
long_query_time = 1
log-error = /data/mysql/log/error.log
max_allowed_packet = 134217728
max_connect_errors = 1000000
max_connections = 2000
myisam_sort_buffer_size = 33554432
#myisam_recover = 1
join_buffer_size = 8388608
tmp_table_size = 33554432
net_buffer_length = 8192
performance_schema = 1
performance_schema_max_table_instances = 200
pid-file = /data/mysql/mysqld.pid
port = 3306
query_cache_size = 0
query_cache_type = 0
read_buffer_size = 20971520
read_rnd_buffer_size = 16M
max_heap_table_size = 33554432
bulk_insert_buffer_size = 134217728
#relay-log = /data2/mysql/log/mysql-relay.log
secure-file-priv = /data/mysql/tmp
server-id = 324532432
skip-slave-start
skip_name_resolve
slave-load-tmpdir = /data/mysql/tmp
slow-query-log-file = /data/mysql/log/mysql-slow.log
slow_query_log = 1
socket = /tmp/mysql.sock
sort_buffer_size = 2097152
table_open_cache = 128
thread_cache_size = 50
tmpdir = /data/mysql/tmp
user = mysql
#wait_timeout = 2880000
transaction_isolation=read-committed
long_query_time=1
sync_binlog=0
innodb_flush_log_at_trx_commit=0
[mysqld_safe]
log-error = /data/mysql/log/error.log
pid-file = /data/mysql/mysqld.pid
保存退出
cd /usr/local/mysql/
初始化數(shù)據(jù)庫(kù):
./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/data/
cd /data/mysql/log/
查看日志,初始化會(huì)生成初始密碼:
tail -f error.log
拷貝啟動(dòng)腳本到系統(tǒng)啟動(dòng)目錄:
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
加入開(kāi)機(jī)啟動(dòng)服務(wù):
chkconfig --add mysql
設(shè)置開(kāi)機(jī)啟動(dòng):
chkconfig mysql on
拷貝命令到系統(tǒng)路徑下,便于全局調(diào)用:
cp /usr/local/mysql/bin/* /usr/local/sbin/
/etc/init.d/mysql start ##啟動(dòng)數(shù)據(jù)庫(kù)
登錄到數(shù)據(jù)庫(kù)內(nèi)修改root用戶(hù)的初始化密碼:
mysql -u root -p --->輸入mysql數(shù)據(jù)庫(kù)root用戶(hù)的密碼
SET PASSWORD = PASSWORD('新密碼'); ##修改root用戶(hù)的密碼。(alter user user() identified by '新密碼';)
到這里整個(gè)初始化過(guò)程就完成了。