一、準備RPM安裝包html
MySQL-server-5.6.33-1.linux_glibc2.5.x86_64node
MySQL-client-5.6.33-1.linux_glibc2.5.x86_64mysql
二、檢查並清理舊版linux
[root@localhost Desktop]# rpm -qa | grep mysql mysql-libs-5.1.66-2.el6_3.x86_64 [root@localhost Desktop]# rpm -e --nodeps mysql-libs-5.1.66-2.el6_3.x86_64 [root@localhost Desktop]# rm -rf /var/lib/mysql* [root@localhost Desktop]# rm -rf /usr/share/mysql*
三、安裝Serverweb
[root@localhost Desktop]# rpm -ivh /root/Desktop/MySQL-server-5.6.33-1.linux_glibc2.5.x86_64.rpm warning: /root/Desktop/MySQL-server-5.6.33-1.linux_glibc2.5.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ########################################### [100%] 1:MySQL-server ########################################### [100%] warning: user mysql does not exist - using root warning: group mysql does not exist - using root 2016-12-13 03:19:31 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2016-12-13 03:19:31 0 [Note] /usr/sbin/mysqld (mysqld 5.6.33) starting as process 35882 ... 2016-12-13 03:19:31 35882 [Note] InnoDB: Using atomics to ref count buffer pool pages 2016-12-13 03:19:31 35882 [Note] InnoDB: The InnoDB memory heap is disabled 2016-12-13 03:19:31 35882 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2016-12-13 03:19:31 35882 [Note] InnoDB: Memory barrier is not used 2016-12-13 03:19:31 35882 [Note] InnoDB: Compressed tables use zlib 1.2.3 2016-12-13 03:19:31 35882 [Note] InnoDB: Using Linux native AIO 2016-12-13 03:19:31 35882 [Note] InnoDB: Using CPU crc32 instructions 2016-12-13 03:19:31 35882 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2016-12-13 03:19:31 35882 [Note] InnoDB: Completed initialization of buffer pool 2016-12-13 03:19:31 35882 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created! 2016-12-13 03:19:31 35882 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB 2016-12-13 03:19:31 35882 [Note] InnoDB: Database physically writes the file full: wait... 2016-12-13 03:19:32 35882 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB 2016-12-13 03:19:35 35882 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB 2016-12-13 03:19:37 35882 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0 2016-12-13 03:19:37 35882 [Warning] InnoDB: New log files created, LSN=45781 2016-12-13 03:19:37 35882 [Note] InnoDB: Doublewrite buffer not found: creating new 2016-12-13 03:19:37 35882 [Note] InnoDB: Doublewrite buffer created 2016-12-13 03:19:37 35882 [Note] InnoDB: 128 rollback segment(s) are active. 2016-12-13 03:19:37 35882 [Warning] InnoDB: Creating foreign key constraint system tables. 2016-12-13 03:19:37 35882 [Note] InnoDB: Foreign key constraint system tables created 2016-12-13 03:19:37 35882 [Note] InnoDB: Creating tablespace and datafile system tables. 2016-12-13 03:19:37 35882 [Note] InnoDB: Tablespace and datafile system tables created. 2016-12-13 03:19:37 35882 [Note] InnoDB: Waiting for purge to start 2016-12-13 03:19:37 35882 [Note] InnoDB: 5.6.33 started; log sequence number 0 A random root password has been set. You will find it in '/root/.mysql_secret'. 2016-12-13 03:19:37 35882 [Note] Binlog end 2016-12-13 03:19:37 35882 [Note] InnoDB: FTS optimize thread exiting. 2016-12-13 03:19:37 35882 [Note] InnoDB: Starting shutdown... 2016-12-13 03:19:38 35882 [Note] InnoDB: Shutdown completed; log sequence number 1625977 2016-12-13 03:19:39 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2016-12-13 03:19:39 0 [Note] /usr/sbin/mysqld (mysqld 5.6.33) starting as process 35906 ... 2016-12-13 03:19:39 35906 [Note] InnoDB: Using atomics to ref count buffer pool pages 2016-12-13 03:19:39 35906 [Note] InnoDB: The InnoDB memory heap is disabled 2016-12-13 03:19:39 35906 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2016-12-13 03:19:39 35906 [Note] InnoDB: Memory barrier is not used 2016-12-13 03:19:39 35906 [Note] InnoDB: Compressed tables use zlib 1.2.3 2016-12-13 03:19:39 35906 [Note] InnoDB: Using Linux native AIO 2016-12-13 03:19:39 35906 [Note] InnoDB: Using CPU crc32 instructions 2016-12-13 03:19:39 35906 [Note] InnoDB: Initializing buffer pool, size = 128.0M 2016-12-13 03:19:39 35906 [Note] InnoDB: Completed initialization of buffer pool 2016-12-13 03:19:39 35906 [Note] InnoDB: Highest supported file format is Barracuda. 2016-12-13 03:19:39 35906 [Note] InnoDB: 128 rollback segment(s) are active. 2016-12-13 03:19:39 35906 [Note] InnoDB: Waiting for purge to start 2016-12-13 03:19:39 35906 [Note] InnoDB: 5.6.33 started; log sequence number 1625977 2016-12-13 03:19:39 35906 [Note] Binlog end 2016-12-13 03:19:39 35906 [Note] InnoDB: FTS optimize thread exiting. 2016-12-13 03:19:39 35906 [Note] InnoDB: Starting shutdown... 2016-12-13 03:19:41 35906 [Note] InnoDB: Shutdown completed; log sequence number 1625987 A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER ! You will find that password in '/root/.mysql_secret'. You must change that password on your first connect, no other statement but 'SET PASSWORD' will be accepted. See the manual for the semantics of the 'password expired' flag. Also, the account for the anonymous user has been removed. In addition, you can run: /usr/bin/mysql_secure_installation which will also give you the option of removing the test database. This is strongly recommended for production servers. See the manual for more instructions. Please report any problems at http://bugs.mysql.com/ The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com New default config file was created as /usr/my.cnf and will be used by default by the server when you start it. You may edit this file to change server settings
四、啓動MySQL服務sql
[root@localhost Desktop]# service mysql start Starting MySQL................... SUCCESS!
五、查看默認密碼數據庫
[root@localhost Desktop]# more /root/.mysql_secret # The random password set for the root user at Tue Dec 13 03:19:37 2016 (local t ime): YPkX6RUWvFNRxYuc
六、安裝Client安全
[root@localhost Desktop]# rpm -ivh /root/Desktop/MySQL-client-5.6.33-1.linux_glibc2.5.x86_64.rpm warning: /root/Desktop/MySQL-client-5.6.33-1.linux_glibc2.5.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing... ########################################### [100%] 1:MySQL-client ########################################### [100%]
七、執行安全向導dom
[root@localhost Desktop]# /usr/bin/mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MySQL to secure it, we'll need the current password for the root user. If you've just installed MySQL, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): YPkX6RUWvFNRxYuc <–初次運行直接回車 OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MySQL root user without the proper authorisation. You already have a root password set, so you can safely answer 'n'. Change the root password? [Y/n] y <– 是否設置root用戶密碼,輸入y並回車或直接回車 New password: 123456 <– 設置root用戶的密碼 Re-enter new password: 123456 <– 再輸入一次你設置的密碼 Password updated successfully! Reloading privilege tables.. ... Success! By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] y <– 是否刪除匿名用戶,生產環境建議刪除,因此直接回車 ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] n <–是否禁止root遠程登陸,根據本身的需求選擇Y/n並回車,建議禁止 ... skipping. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] n <– 是否刪除test數據庫,直接回車 ... skipping. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y <– 是否從新加載權限表,直接回車 ... Success! All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL! Cleaning up...
八、配置my.cnfsocket
[root@localhost Desktop]# cp /usr/share/mysql/my-default.cnf /etc/my.cnf
# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the # *** default location during install, and will be replaced if you # *** upgrade to a newer version of MySQL. [mysqld] #socket = /var/lib/mysql/mysql.sock #datadir = /var/lib/mysql/mysql character-set-server=utf8 lower_case_table_names=1 # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. # basedir = ..... # datadir = ..... # port = ..... # server_id = ..... # socket = ..... # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
九、重啓服務
[root@localhost Desktop]# service mysql restart Shutting down MySQL.. SUCCESS! Starting MySQL.. SUCCESS!
十、關閉防火牆
[root@localhost Desktop]# service iptables stop iptables: Flushing firewall rules: [ OK ] iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Unloading modules: [ OK ]
十一、測試鏈接
參考資料:
http://www.linuxidc.com/Linux/2015-01/111744.htm