1.詳細描安裝的過程
1.1關閉防火牆
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機啟動
firewall-cmd --state #查看默認防火牆狀態(關閉后顯示notrunning,開啟后顯示running)
1.2 檢查是否安裝NySQL,如果安裝 卸載之
rpm -qa |grep mysql
yum remove mysql*
1.3 檢查是否安裝MariaDB,如果安裝 卸載之(重要)
rpm -qa |grep mariadb
yum remove mariadb*
1.4 新增用戶/組 參數文件
groupadd mysql
useradd -d /home/mysql -g mysql -m mysql
passwd mysql
mysql
vi ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/u01/MySQL5.7/bin
export PATH
[mysql@localhost ~]$ source .bash_profile
1.5 規划目錄 賦權限
mkdir -p /u01/MySQL5.7
mkdir -p /MySQL/my3306/data
mkdir -p /MySQL/my3306/log/iblog
mkdir -p /MySQL/my3306/log/binlog
mkdir -p /MySQL/my3306/run
mkdir -p /MySQL/my3306/tmp
chown -R mysql:mysql /MySQL/my3306
chown -R mysql:mysql /u01/MySQL5.7
##chown -R 755 /MySQL/my3307
1.6 下載mysql安裝介質到目標機器
[root@localhost ~]# cd /u01/MySQL5.7
[root@localhost MySQL5.7]# ll
total 0
[root@localhost MySQL5.7]# ll
total 696028
-rw-r--r--. 1 mysql mysql 712729170 May 14 01:42 mysql-5.7.22-el7-x86_64.tar.gz
1.8 解壓
[mysql@localhost MySQL5.7]# tar -xzvf mysql-5.7.22-el7-x86_64.tar.gz
[mysql@localhost MySQL5.7]# mv /u01/MySQL5.7/mysql-5.7.22-el7-x86_64/* /u01/MySQL5.7/
1.9初始化數據庫
[mysql@localhost ~]$ mysqld --initialize --user=mysql --basedir=/u01/MySQL5.7 --datadir=/MySQL/my3306/data --explicit_defaults_for_timestamp
2018-05-14T05:52:52.741612Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2018-05-14T05:52:52.742026Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2018-05-14T05:52:53.946033Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-05-14T05:52:54.104581Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-05-14T05:52:54.201291Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 0b79b507-573b-11e8-89dd-000c29a1762c.
2018-05-14T05:52:54.203218Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-05-14T05:52:54.210927Z 1 [Note] A temporary password is generated for root@localhost: ;c_tca9sR;s5
由上可知,初始化的root 密碼為;c_tca9sR;s5
1.10編輯參數文件 my.cnf
vi /MySQL/my3306/my.cnf
[mysqld]
#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
basedir=/u01/MySQL5.7 #介質目錄
datadir=/MySQL/my3306/data #數據目錄
port=3306 #端口
pid-file = /MySQL/my3306/data/mysql.pid #進程id
user = mysql #啟動用戶
socket=/MySQL/my3306/run/mysql.sock #sock文件地址
bind-address = 0.0.0.0 #綁定ip 這里表示綁定所有ip
server-id = 1 #用於復制環境鍾標識實例,這個在復制環境里唯一
character-set-server = utf8 #服務端默認字符集,很重要,錯誤設置會出現亂碼
max_connections = 1000 #允許客戶端並發連接的最大數量
max_connect_errors = 6000 #如果客戶端嘗試連接的錯誤數量超過這個參數設置的值,則服務器不再接受新的客戶端連接。
open_files_limit = 65535 #操作系統允許MySQL服務打開的文件數量。
table_open_cache = 128 #所有線程能打開的表的數量
max_allowed_packet = 4M #網絡傳輸時單個數據包的大小。
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30
log_error = /MySQL/my3306/data/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /MySQL/my3306/data/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
#lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
#default-storage-engine = MyISAM
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
#lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
#default-storage-engine = MyISAM
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
[client]
port=3306
socket=/MySQL/my3306/run/mysql.sock
[mysql]
socket=/MySQL/my3306/run/mysql.sock
1.11拷貝my.cnf 以及 mysql.server
cp /MySQL/my3306/my.cnf /etc/my.cnf
cp /u01/MySQL5.7/support-files/mysql.server /etc/init.d/mysqld
1.12編輯 /etc/init.d/mysqld
#添加一下兩項
basedir=/u01/MySQL5.7
datadir=/MySQL/my3306/data
1.13.啟動數據庫
[mysql@localhost ~]$ service mysqld start
Starting MySQL.. SUCCESS!
1.14.連接數據庫 更新初始密碼
[mysql@localhost ~]$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22-log
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql>
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> set PASSWORD=PASSWORD('root');
Query OK, 0 rows affected, 1 warning (0.03 sec)
mysql> flush privileges;
1.15.配置mysql開機啟動
[root@localhost ~]# chkconfig mysqld on
[root@localhost ~]# chkconfig
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off