環境部署:VMware10.0+CentOS6.9(64位)+MySQL5.7.19(64位)
一、操作系統調整
# 更改時區 1、先查看時區 [root@localhost ~]# date -R Tue, 29 Aug 2017 20:13:00 -0700 2、將Asia/shanghai-上海時區寫入當前時區 [root@localhost ~]# cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime cp: overwrite '/etc/localtime'? y 3、再次查看時區 [root@localhost ~]# date -R Wed, 30 Aug 2017 11:14:24 +0800 # 更改主機名 1、原主機名 [root@localhost ~]# uname -a Linux localhost.localdomain 2.6.32-696.el6.x86_64 #1 SMP Tue Mar 21 19:29:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux [root@localhost ~]# hostname localhost.localdomain 2、先備份原文件再修改 [root@localhost ~]# cp /etc/sysconfig/network /etc/sysconfig/network.`date +%Y%m%d.%H%M%S` [root@localhost ~]# ll /etc/sysconfig |grep network -rw-r--r--. 1 root root 46 Aug 30 2017 network -rw-r--r--. 1 root root 46 Aug 30 11:21 network.20170830.112114 drwxr-xr-x. 4 root root 4096 May 11 2016 networking drwxr-xr-x. 2 root root 4096 Aug 30 2017 network-scripts [root@localhost ~]# vim /etc/sysconfig/network NETWORKING=yes HOSTNAME=ZST1 [root@localhost ~]# [root@localhost ~]# cp /etc/hosts /etc/hosts.`date +%Y%m%d.%H%M%S` [root@localhost ~]# vim /etc/hosts #添加記錄,不要修改默認的127.0.0.1跟::1的記錄,其他的系統服務會使用到的 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.85.132 ZST1 192.168.85.133 ZST2 192.168.85.134 ZST3 [root@localhost ~]# # 設定linux運行級別為3(文本模式) 1、查看當前運行的模式 [root@localhost ~]# runlevel N 5 2、設定linux運行級別為3 [root@localhost ~]# vim /etc/inittab id:3:initdefault: 3、重啟服務器 [root@localhost ~]# reboot
1、刪除系統自帶的舊rpm包(add) [root@ZST1 ~]# rpm -qa | grep -i mysql mysql-libs-5.1.73-8.el6_8.x86_64 [root@ZST1 ~]# yum -y remove mysql-libs-5.1* [root@ZST1 ~]# whereis mysql mysql: 2、官網下載二進制包Linux Generic,下載頁面可查看各版本的Change History,下載完成后驗證md5 [root@ZST1 ~]# mkdir -p /tools [root@ZST1 tools]# cd /tools [root@ZST1 tools]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz [root@ZST1 tools]# md5sum mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz dbe7e5e820377c29d8681005065e5728 mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz 3、創建帳號(運行服務的帳戶都不能登錄) [root@ZST1 tools]# groupadd mysql [root@ZST1 tools]# useradd -g mysql -d /usr/local/mysql -s /sbin/nologin -M mysql [root@ZST1 tools]# id mysql uid=501(mysql) gid=501(mysql) groups=501(mysql) [root@ZST1 tools]# 4、基本軟件安裝 [root@ZST1 tools]# mkdir /opt/mysql [root@ZST1 tools]# cd /opt/mysql [root@ZST1 mysql]# tar zxvf /tools/mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz [root@ZST1 mysql]# cd /usr/local/ [root@ZST1 local]# ln -s /opt/mysql/mysql-5.7.19-linux-glibc2.12-x86_64 mysql [root@ZST1 local]# chown -R mysql:mysql mysql/ 這里使用ln創建軟鏈接的目的?為何不直接把/opt/mysql/mysql-5.7.19-linux-glibc2.12-x86_64目錄下的內容拷貝到/usr/local/mysql下 5、創建數據庫相關的目錄 配置文件:/etc/my.cnf /data 是一個單獨掛載的一個分區 datadir /data/mysql/mysql3306/data binlog /data/mysql/mysql3306/logs /data/mysql/mysql3306/tmp [root@ZST1 local]# mkdir /data/mysql/mysql3306/{data,logs,tmp} -p 修改屬主,add [root@ZST1 local]# chown -R mysql:mysql /data/mysql/ 6、初始化 [root@ZST1 local]# cd /usr/local/mysql [root@ZST1 mysql]# ./bin/mysqld --defaults-file=/etc/my.cnf --initialize 之前版本(5.6,5.5,5.1)使用mysql_basedir/script/mysql_install_db;5.7的./bin/mysql_install_db已被廢棄 --initialize會生成一個隨機密碼(error.log);--initialize-insecure不會生成密碼 --datadir目錄下不能有數據文件 [root@ZST1 mysql]# find / -name mysql_install_db 獲取密碼,add [root@ZST1 mysql]# cat /data/mysql/mysql3306/data/error.log |grep password 7、啟動 [root@ZST1 mysql]# cp support-files/mysql.server /etc/init.d/mysql [root@ZST1 mysql]# /etc/init.d/mysql start [root@ZST1 mysql]# service mysql start 8、連接 去掉my.cnf中--skip-grant-tables前的注釋,重啟數據庫服務(如果能知道第6步生成的密碼就不需這樣折騰) [root@ZST1 mysql]# ./bin/mysql -uroot [root@ZST1 mysql]# ./bin/mysql -S /tmp/mysql3306.sock 進入數據庫,嘗試使用alter user修改密碼 root@localhost [(none)]> alter user root@localhost identified by 'mysql5719'; ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement root@localhost [(none)]> use mysql; root@localhost [mysql]> update user set authentication_string=password('mysql5719') where User='root'; Query OK, 1 row affected, 1 warning (0.03 sec) Rows matched: 1 Changed: 1 Warnings: 1 退出,注釋my.cnf中--skip-grant-tables,重啟數據庫服務,再重新進入 root@localhost [mysql]> exit [root@ZST1 mysql]# ./bin/mysql -uroot -p Enter password: 鍵入新密碼 root@localhost [(none)]> show databases; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. 出現這個錯誤的原因是user表中的password_expired字段取值為Y,密碼過期需修改 root@localhost [(none)]> alter user 'root'@'localhost' identified by 'mysql5719'; root@localhost [(none)]> exit 9、配置PATH mysql未添加環境變量前 [root@ZST1 mysql]# mysql -uroot -p bash: mysql: command not found [root@ZST1 mysql]# echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile [root@ZST1 mysql]# source /etc/profile [root@ZST1 mysql]# echo $PATH [root@ZST1 mysql]# mysql -uroot -p Enter password: 鍵入正確密碼 10、關閉mysql [root@ZST1 mysql]# /etc/init.d/mysql stop
三、遇到的問題
2.5中沒有修改數據庫相關的目錄的屬主 [root@ZST1 mysql]# service mysql start Starting MySQL. ERROR! The server quit without updating PID file (/data/mysql/mysql3306/data/mysql.pid). 查看錯誤日志 [root@ZST1 mysql]# tail -n 10 /data/mysql/mysql3306/data/error.log 2017-08-31T09:30:07.528203Z 0 [Warning] The syntax '--log_warnings/-W' is deprecated and will be removed in a future release. Please use '--log_error_verbosity' instead. 2017-08-31T09:30:07.528381Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2017-08-31T09:30:07.544406Z 0 [Warning] Insecure configuration for --secure-file-priv: Location is accessible to all OS users. Consider choosing a different directory. 2017-08-31T09:30:07.544477Z 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.7.19-log) starting as process 28477 ... mysqld: File '/data/mysql/mysql3306/logs/mysql-bin.index' not found (Errcode: 13 - Permission denied) 2017-08-31T09:30:07.548527Z 0 [ERROR] Aborting 2017-08-31T09:30:07.548544Z 0 [Note] Binlog end 2017-08-31T09:30:07.548838Z 0 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete logs目錄的權限問題(Permission denied) [root@ZST1 mysql]# ll /data/mysql/mysql3306 total 12 drwxr-xr-x. 2 mysql mysql 4096 Aug 31 17:30 data drwxr-xr-x. 2 root root 4096 Aug 31 17:25 logs drwxr-xr-x. 2 root root 4096 Aug 31 17:25 tmp 修改目錄屬主信息 [root@ZST1 mysql]# cd /data/mysql/mysql3306 [root@ZST1 mysql3306]# chown -R mysql:mysql logs [root@ZST1 mysql3306]# chown -R mysql:mysql tmp 再次啟動失敗 [root@ZST1 mysql]# /etc/init.d/mysql start Starting MySQL...... ERROR! The server quit without updating PID file (/data/mysql/mysql3306/data/mysql.pid). 查看錯誤日志 [root@ZST1 data]# tail -n 100 /data/mysql/mysql3306/data/error.log 2017-08-31T09:52:57.010606Z 0 [Note] InnoDB: The first innodb_system data file 'ibdata1' did not exist. A new tablespace will be created! 2017-08-31T09:52:57.011019Z 0 [Note] InnoDB: Setting file './ibdata1' size to 100 MB. Physically writing the file full; Please wait ... 2017-08-31T09:52:57.011542Z 0 [Note] InnoDB: Progress in MB: 100 2017-08-31T09:52:57.115478Z 0 [Note] InnoDB: File './ibdata1' size is now 100 MB. 2017-08-31T09:52:57.116269Z 0 [Note] InnoDB: Setting log file ./ib_logfile101 size to 100 MB 2017-08-31T09:52:57.116414Z 0 [Note] InnoDB: Progress in MB: 100 2017-08-31T09:52:57.600744Z 0 [Note] InnoDB: Setting log file ./ib_logfile1 size to 100 MB 2017-08-31T09:52:57.600967Z 0 [Note] InnoDB: Progress in MB: 100 2017-08-31T09:52:58.127698Z 0 [Note] InnoDB: Setting log file ./ib_logfile2 size to 100 MB 2017-08-31T09:52:58.127915Z 0 [Note] InnoDB: Progress in MB: 100 2017-08-31T09:52:58.666114Z 0 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0 2017-08-31T09:52:58.666227Z 0 [Warning] InnoDB: New log files created, LSN=45790 2017-08-31T09:52:58.666254Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables 2017-08-31T09:52:58.666444Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ... 2017-08-31T09:52:58.681658Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB. 2017-08-31T09:52:58.681940Z 0 [Note] InnoDB: Doublewrite buffer not found: creating new 2017-08-31T09:52:58.851112Z 0 [Note] InnoDB: Doublewrite buffer created 2017-08-31T09:52:58.902414Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active. 2017-08-31T09:52:58.902485Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active. 2017-08-31T09:52:58.911638Z 0 [Warning] InnoDB: Creating foreign key constraint system tables. 2017-08-31T09:52:58.956602Z 0 [Note] InnoDB: Foreign key constraint system tables created 2017-08-31T09:52:58.956727Z 0 [Note] InnoDB: Creating tablespace and datafile system tables. 2017-08-31T09:52:58.957381Z 0 [Note] InnoDB: Tablespace and datafile system tables created. 2017-08-31T09:52:58.957432Z 0 [Note] InnoDB: Creating sys_virtual system tables. 2017-08-31T09:52:58.957842Z 0 [Note] InnoDB: sys_virtual table created 2017-08-31T09:52:59.023019Z 0 [Note] InnoDB: Waiting for purge to start 2017-08-31T09:52:59.073741Z 0 [Note] InnoDB: 5.7.19 started; log sequence number 0 2017-08-31T09:52:59.116756Z 0 [Note] Plugin 'FEDERATED' is disabled. mysqld: Table 'mysql.plugin' doesn't exist 2017-08-31T09:52:59.117295Z 0 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it. 2017-08-31T09:52:59.173209Z 0 [Note] Salting uuid generator variables, current_pid: 30669, server_start_time: 1504173176, bytes_sent: 0, 2017-08-31T09:52:59.183122Z 0 [Note] Generated uuid: '2bc37fda-8e32-11e7-8369-000c29c1025c', server_start_time: 8632556062243312709, bytes_sent: 56834352 2017-08-31T09:52:59.183198Z 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: 2bc37fda-8e32-11e7-8369-000c29c1025c. 2017-08-31T09:52:59.185831Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened. 2017-08-31T09:52:59.188080Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key 2017-08-31T09:52:59.188112Z 0 [Note] Server hostname (bind-address): '*'; port: 3306 2017-08-31T09:52:59.198187Z 0 [Note] IPv6 is available. 2017-08-31T09:52:59.198309Z 0 [Note] - '::' resolves to '::'; 2017-08-31T09:52:59.198368Z 0 [Note] Server socket created on IP: '::'. 2017-08-31T09:52:59.232943Z 0 [Warning] Failed to open optimizer cost constant tables 2017-08-31T09:52:59.233342Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist 2017-08-31T09:52:59.233452Z 0 [ERROR] Aborting 2017-08-31T09:52:59.233515Z 0 [Note] Binlog end 2017-08-31T09:52:59.235765Z 0 [Note] Shutting down plugin 'ngram' 2017-08-31T09:52:59.235798Z 0 [Note] Shutting down plugin 'BLACKHOLE' 2017-08-31T09:52:59.235810Z 0 [Note] Shutting down plugin 'ARCHIVE' 2017-08-31T09:52:59.235818Z 0 [Note] Shutting down plugin 'partition' 2017-08-31T09:52:59.235826Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL' 2017-08-31T09:52:59.235834Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES' 2017-08-31T09:52:59.235841Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES' 2017-08-31T09:52:59.235848Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS' 2017-08-31T09:52:59.235855Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN' 2017-08-31T09:52:59.235863Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS' 2017-08-31T09:52:59.235870Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS' 2017-08-31T09:52:59.235877Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES' 2017-08-31T09:52:59.235884Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS' 2017-08-31T09:52:59.235891Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES' 2017-08-31T09:52:59.235898Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE' 2017-08-31T09:52:59.235905Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE' 2017-08-31T09:52:59.235913Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG' 2017-08-31T09:52:59.235919Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED' 2017-08-31T09:52:59.235927Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED' 2017-08-31T09:52:59.235934Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD' 2017-08-31T09:52:59.235941Z 0 [Note] Shutting down plugin 'INNODB_METRICS' 2017-08-31T09:52:59.235948Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO' 2017-08-31T09:52:59.235955Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS' 2017-08-31T09:52:59.235962Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU' 2017-08-31T09:52:59.235969Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE' 2017-08-31T09:52:59.235985Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET' 2017-08-31T09:52:59.235994Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX' 2017-08-31T09:52:59.236001Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET' 2017-08-31T09:52:59.236008Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM' 2017-08-31T09:52:59.236016Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET' 2017-08-31T09:52:59.236023Z 0 [Note] Shutting down plugin 'INNODB_CMP' 2017-08-31T09:52:59.236030Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS' 2017-08-31T09:52:59.236038Z 0 [Note] Shutting down plugin 'INNODB_LOCKS' 2017-08-31T09:52:59.236045Z 0 [Note] Shutting down plugin 'INNODB_TRX' 2017-08-31T09:52:59.236052Z 0 [Note] Shutting down plugin 'InnoDB' 2017-08-31T09:52:59.236349Z 0 [Note] InnoDB: FTS optimize thread exiting. 2017-08-31T09:52:59.236499Z 0 [Note] InnoDB: Starting shutdown... 2017-08-31T09:52:59.337034Z 0 [Note] InnoDB: Dumping buffer pool(s) to /data/mysql/mysql3306/data/ib_buffer_pool 2017-08-31T09:52:59.337528Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 170831 17:52:59 2017-08-31T09:53:00.862954Z 0 [Note] InnoDB: Shutdown completed; log sequence number 1209961 2017-08-31T09:53:00.863526Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1" 2017-08-31T09:53:00.863560Z 0 [Note] Shutting down plugin 'MEMORY' 2017-08-31T09:53:00.863576Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA' 2017-08-31T09:53:00.863762Z 0 [Note] Shutting down plugin 'MRG_MYISAM' 2017-08-31T09:53:00.863777Z 0 [Note] Shutting down plugin 'MyISAM' 2017-08-31T09:53:00.865027Z 0 [Note] Shutting down plugin 'CSV' 2017-08-31T09:53:00.865062Z 0 [Note] Shutting down plugin 'sha256_password' 2017-08-31T09:53:00.865075Z 0 [Note] Shutting down plugin 'mysql_native_password' 2017-08-31T09:53:00.865415Z 0 [Note] Shutting down plugin 'binlog' 2017-08-31T09:53:00.868573Z 0 [Note] /usr/local/mysql/bin/mysqld: Shutdown complete 重新初始化 [root@ZST1 mysql]# pwd /usr/local/mysql [root@ZST1 mysql]# ./bin/mysqld --defaults-file=/etc/my.cnf --initialize 2017-08-31T09:54:45.865304Z 0 [Warning] The syntax '--log_warnings/-W' is deprecated and will be removed in a future release. Please use '--log_error_verbosity' instead. 2017-08-31T09:54:45.865492Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2017-08-31T09:54:45.865561Z 0 [Note] Ignoring --secure-file-priv value as server is running with --initialize(-insecure) or --bootstrap. 2017-08-31T09:54:45.865593Z 0 [Note] ./bin/mysqld (mysqld 5.7.19-log) starting as process 30720 ... 2017-08-31T09:54:45.868650Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting. 2017-08-31T09:54:45.868696Z 0 [ERROR] Aborting 2017-08-31T09:54:45.868723Z 0 [Note] Binlog end 2017-08-31T09:54:45.868950Z 0 [Note] ./bin/mysqld: Shutdown complete 數據目錄有文件存在(data directory has files in it),2.6也提到初始化時--datadir目錄下不能有數據文件 刪除/data/mysql/mysql3306/{data,logs,tmp}目錄下的所有文件(夾),再重新初始化
對於Errcode可以使用perror命令查看錯誤描述
[root@ZST1 ~]# /usr/local/mysql/bin/perror 13 OS error code 13: Permission denied
四、my.cnf
#my.cnf [client] port = 3306 socket = /tmp/mysql3306.sock [mysql] prompt="\\u@\\h,\\p [\\d]>\\_" #pager="less -i -n -S" #tee=/opt/mysql/query.log no-auto-rehash [mysqld] #misc user = mysql basedir = /usr/local/mysql datadir = /data/mysql/mysql3306/data port = 3306 socket = /tmp/mysql3306.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 #file #@secure-file-priv=/tmp #symi replication #rpl_semi_sync_master_enabled=1 #rpl_semi_sync_master_timeout=1000 # 1 second #rpl_semi_sync_slave_enabled=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 = 1003306 log-bin = /data/mysql/mysql3306/logs/mysql-bin max_binlog_size = 256M sync_binlog = 0 expire_logs_days = 10 #procedure log_bin_trust_function_creators=1 #file secure_file_priv="/tmp" # gtid-mode = on enforce-gtid-consistency=1 #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_io_capacity = 2000 transaction_isolation = READ-COMMITTED innodb_flush_method = O_DIRECT
問題:能否使用二進制包在同一機器上搭建多實例?多實例主要是my.cnf怎么區分?
補一、宿主機用Navicat連接虛擬機上的MySQL實例
1、宿主機用Navicat連接虛擬機上的MySQL實例 2003 - Cannot connect to MySQL server on '192.168.85.132'(10060) 2、宿主機ping、telnet虛擬機 C:\Users\Administrator>ping 192.168.85.132 正在 Ping 192.168.85.132 具有 32 字節的數據: 來自 192.168.85.132 的回復: 字節=32 時間<1ms TTL=64 來自 192.168.85.132 的回復: 字節=32 時間<1ms TTL=64 來自 192.168.85.132 的回復: 字節=32 時間<1ms TTL=64 來自 192.168.85.132 的回復: 字節=32 時間<1ms TTL=64 192.168.85.132 的 Ping 統計信息: 數據包: 已發送 = 4,已接收 = 4,丟失 = 0 (0% 丟失), 往返行程的估計時間(以毫秒為單位): 最短 = 0ms,最長 = 0ms,平均 = 0ms C:\Users\Administrator>telnet 192.168.85.132 3306 正在連接192.168.85.132...無法打開到主機的連接。 在端口 3306: 連接失敗 3、虛擬機檢查防火牆 [root@ZST1 ~]# service iptables status Table: filter Chain INPUT (policy ACCEPT) num target prot opt source destination 1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED 2 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 4 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22 5 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT) num target prot opt source destination 1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT) num target prot opt source destination 暫時關閉防火牆,后期添加入站規則 [root@ZST1 ~]# service iptables stop [root@ZST1 ~]# cp /etc/sysconfig/iptables /etc/sysconfig/iptables.`date +%Y%m%d.%H%M%S` -I作為第一條規則插入,-A作為最后一條規則插入 [root@ZST1 ~]# iptables -I INPUT -p tcp --dport 3306 -j ACCEPT [root@ZST1 ~]# service iptables save [root@ZST1 ~]# service iptables restart 4、宿主機Navicat連接虛擬機上的MySQL實例 1045-Access denied for user 'root'@'192.168.85.1'(using password:Yes) 用戶表中沒有授權(只有root@localhost) 5、mysql創建新用戶 [root@ZST1 ~]# mysql -uroot -p root@localhost,mysql3306.sock [(none)]> grant all privileges on *.* to mydba@"192.168.85.%" Identified by "mysql5719"; 之后就可以從宿主機用Navicat連接虛擬機上的MySQL實例 可使用rename user修改User和Host信息 root@localhost,mysql3306.sock [(none)]> rename user 'mydba'@'192.168.85.%' TO 'mydba'@'localhost'; root@localhost,mysql3306.sock [(none)]> show grants for 'mydba'@'192.168.85.%'; rename user后不需要flush privileges,會直接更新內存中的權限信息; Navicat打開的命令列界面,不會受my.cnf中的prompt影響
使用rename user修改User和Host信息,rename user后不需要flush privileges,會直接更新內存中的權限信息;
補二、二進制包/源碼安裝方式的MySQL卸載
1、檢查MySQL服務並關閉服務進程 [root@ZST1 ~]# ps -ef | grep mysql root 2525 1 0 10:23 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql/mysql3306/data --pid-file=/data/mysql/mysql3306/data/mysql.pid mysql 3487 2525 0 10:23 pts/0 00:00:05 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql/mysql3306/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=error.log --open-files-limit=65535 --pid-file=/data/mysql/mysql3306/data/mysql.pid --socket=/tmp/mysql3306.sock --port=3306 root 3680 2465 0 10:33 pts/0 00:00:00 mysql -uroot -p root 4887 3732 0 12:25 pts/1 00:00:00 grep mysql [root@ZST1 ~]# service mysql status SUCCESS! MySQL running (3487) [root@ZST1 ~]# service mysql stop Shutting down MySQL.. SUCCESS! [root@ZST1 ~]# service mysql status ERROR! MySQL is not running [root@ZST1 ~]# 2、查找MySQL的安裝目錄並徹底刪除 [root@ZST1 ~]# whereis mysql mysql: /usr/lib64/mysql /usr/local/mysql /usr/share/mysql [root@ZST1 ~]# find / -name mysql /usr/local/mysql /usr/lib64/mysql /usr/share/mysql /var/spool/mail/mysql /opt/mysql /opt/mysql/mysql-5.7.19-linux-glibc2.12-x86_64/bin/mysql /opt/mysql/mysql-5.7.19-linux-glibc2.12-x86_64/include/mysql /etc/rc.d/init.d/mysql /data/mysql /data/mysql/mysql3306/data/mysql [root@ZST1 ~]# 和原文稍有不同,ZST1之前存在mysql-libs [root@ZST1 ~]# rpm -qa|grep -i mysql mysql-libs-5.1.73-8.el6_8.x86_64 [root@ZST1 ~]# yum -y remove mysql-libs-5.1.73-8.el6_8.x86_64 [root@ZST1 ~]# ll /etc |grep my.cnf -rw-r--r--. 1 root root 2469 Sep 1 15:30 my.cnf.rpmsave [root@ZST1 ~]# whereis mysql mysql: /usr/local/mysql [root@ZST1 ~]# find / -name mysql /usr/local/mysql /var/spool/mail/mysql /opt/mysql /opt/mysql/mysql-5.7.19-linux-glibc2.12-x86_64/bin/mysql /opt/mysql/mysql-5.7.19-linux-glibc2.12-x86_64/include/mysql /etc/rc.d/init.d/mysql /data/mysql /data/mysql/mysql3306/data/mysql [root@ZST1 ~]# rm -rf /var/spool/mail/mysql [root@ZST1 ~]# rm -rf /etc/rc.d/init.d/mysql [root@ZST1 ~]# rm -rf /data/mysql/mysql3306 3、刪除一些配置文件 配置文件一般有/etc/my.cnf 或/etc/init.d/mysql.server,視具體安裝配置情況而定。 4、刪除MySQL用戶以及用戶組 [root@ZST1 ~]# id mysql uid=501(mysql) gid=501(mysql) groups=501(mysql) [root@ZST1 ~]# userdel mysql $PATH里面還有mysql信息,第3、4步暫時不處理
在前面刪除的基礎上重新使用二進制包安裝MySQL
5、創建數據庫相關的目錄 [root@ZST1 ~]# mkdir /data/mysql/mysql3306/{data,logs,tmp} -p [root@ZST1 ~]# chown -R mysql:mysql /data/mysql/ 6、初始化 [root@ZST1 ~]# cd /usr/local/mysql [root@ZST1 mysql]# mv /etc/my.cnf.rpmsave /etc/my.cnf [root@ZST1 mysql]# ./bin/mysqld --defaults-file=/etc/my.cnf --initialize 找不到那個所謂的~/.mysql_secret文件 [root@ZST1 mysql]# more ~/.mysql_secret /root/.mysql_secret: No such file or directory 初始密碼從error.log中查找 [root@ZST1 mysql]# cat /data/mysql/mysql3306/data/error.log |grep password 2017-09-05T08:27:25.396068Z 1 [Note] A temporary password is generated for root@localhost: FpN=_tXkg2zW
