Centos 7上安裝及配置MySQL 5.6.26

1、卸載系統自帶Mariadb

Centos7 已經不自帶MySQL,自帶內部集成了Mariadb,而安裝MySQL的話會和Mariadb的文件衝突,所以需要先卸載掉Mariadb,再安裝MySQL。

[root@langer ~]# rpm -qa | grep mariadb                     // 列出mariadb相關已安裝包

mariadb-libs-5.5.40-1.el7_0.x86_64                      // 本例中找到的相關RPM包

[root@langer ~]# rpm -e --nodeps mariadb-libs-5.5.40-1.el7_0.x86_64      // 卸載上面找到的所有相關RPM包

[root@langer ~]# rpm -qa | grep mariadb                         // 在卸載完以後再次用此命令來查看

[root@langer~]#                                         // 未查找到,表明mariadb已經卸載成功!!

2、準備MySQL安裝包

我們只需要MySQL的兩個包:

下載地址

MySQL-server-5.6.26-1.el7.x86_64.rpm 鏈接:http://pan.baidu.com/s/1kVKvcpT 密碼:swyc
MySQL-client-5.6.26-1.el7.x86_64.rpm 鏈接:http://pan.baidu.com/s/1i5jRwep 密碼:29cg

將這些包下載來傳到前面說的服務器的/data/AtlassianResource中

3、開始安裝MySQL

先裝MySQL-server,再裝MySQL-client:

[root@langer ~]# yum install -y perl-Module-Install.noarch

[root@langer ~]# yum -y install perl

[root@langer ~]# yum -y install libaio                                                                   // CentOS7最小版本安裝MySQL找不到Perl的依賴包的解決辦法,或MySQL通過rpm包方式安裝時,不會執行mysql_install_db從而生成/root/.mysql_secret等,是缺少上面這3個依賴,所以我們先裝下(如果已有會提示你無需安裝),以免安裝過程出錯要卸載重裝更麻煩。

[root@langer ~]# cd /data/AtlassianResource                                                // 進入AtlassianResource目錄下

[root@langer AtlassianResource]# rpm -ivh MySQL-server-5.6.26-1.el7.x86_64.rpm             // 執行安裝MySQL-server,安裝過程有如下提示(若Centos最小化安裝,可能還需要依賴包:yum -y install libaio、yum -y install perl和yum -y install perl-Module-Install.noarch):

Preparing...                ########################################### [100%]

   1:MySQL-server           ########################################### [100%]

warning: user mysql does not exist - using root

warning: group mysql does not exist - using root

2015-01-20 13:10:42 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2015-01-20 13:10:42 5645 [Note] InnoDB: Using atomics to ref count buffer pool pages

2015-01-20 13:10:42 5645 [Note] InnoDB: The InnoDB memory heap is disabled

2015-01-20 13:10:42 5645 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

2015-01-20 13:10:42 5645 [Note] InnoDB: Memory barrier is not used

2015-01-20 13:10:42 5645 [Note] InnoDB: Compressed tables use zlib 1.2.3

2015-01-20 13:10:42 5645 [Note] InnoDB: Using Linux native AIO

2015-01-20 13:10:42 5645 [Note] InnoDB: Not using CPU crc32 instructions

2015-01-20 13:10:42 5645 [Note] InnoDB: Initializing buffer pool, size = 128.0M

2015-01-20 13:10:42 5645 [Note] InnoDB: Completed initialization of buffer pool

2015-01-20 13:10:42 5645 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!

2015-01-20 13:10:42 5645 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB

2015-01-20 13:10:42 5645 [Note] InnoDB: Database physically writes the file full: wait...

2015-01-20 13:10:42 5645 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB

2015-01-20 13:10:42 5645 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB

2015-01-20 13:10:43 5645 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0

2015-01-20 13:10:43 5645 [Warning] InnoDB: New log files created, LSN=45781

2015-01-20 13:10:43 5645 [Note] InnoDB: Doublewrite buffer not found: creating new

2015-01-20 13:10:43 5645 [Note] InnoDB: Doublewrite buffer created

2015-01-20 13:10:43 5645 [Note] InnoDB: 128 rollback segment(s) are active.

2015-01-20 13:10:43 5645 [Warning] InnoDB: Creating foreign key constraint system tables.

2015-01-20 13:10:43 5645 [Note] InnoDB: Foreign key constraint system tables created

2015-01-20 13:10:43 5645 [Note] InnoDB: Creating tablespace and datafile system tables.

2015-01-20 13:10:43 5645 [Note] InnoDB: Tablespace and datafile system tables created.

2015-01-20 13:10:43 5645 [Note] InnoDB: Waiting for purge to start

2015-01-20 13:10:43 5645 [Note] InnoDB: 5.6.22 started; log sequence number 0

A random root password has been set. You will find it in '/root/.mysql_secret'.

2015-01-20 13:10:44 5645 [Note] Binlog end

2015-01-20 13:10:44 5645 [Note] InnoDB: FTS optimize thread exiting.

2015-01-20 13:10:44 5645 [Note] InnoDB: Starting shutdown...

2015-01-20 13:10:45 5645 [Note] InnoDB: Shutdown completed; log sequence number 1625977

 

 

2015-01-20 13:10:45 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2015-01-20 13:10:45 5667 [Note] InnoDB: Using atomics to ref count buffer pool pages

2015-01-20 13:10:45 5667 [Note] InnoDB: The InnoDB memory heap is disabled

2015-01-20 13:10:45 5667 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins

2015-01-20 13:10:45 5667 [Note] InnoDB: Memory barrier is not used

2015-01-20 13:10:45 5667 [Note] InnoDB: Compressed tables use zlib 1.2.3

2015-01-20 13:10:45 5667 [Note] InnoDB: Using Linux native AIO

2015-01-20 13:10:45 5667 [Note] InnoDB: Not using CPU crc32 instructions

2015-01-20 13:10:45 5667 [Note] InnoDB: Initializing buffer pool, size = 128.0M

2015-01-20 13:10:45 5667 [Note] InnoDB: Completed initialization of buffer pool

2015-01-20 13:10:45 5667 [Note] InnoDB: Highest supported file format is Barracuda.

2015-01-20 13:10:45 5667 [Note] InnoDB: 128 rollback segment(s) are active.

2015-01-20 13:10:45 5667 [Note] InnoDB: Waiting for purge to start

2015-01-20 13:10:45 5667 [Note] InnoDB: 5.6.22 started; log sequence number 1625977

2015-01-20 13:10:45 5667 [Note] Binlog end

2015-01-20 13:10:45 5667 [Note] InnoDB: FTS optimize thread exiting.

2015-01-20 13:10:45 5667 [Note] InnoDB: Starting shutdown...

2015-01-20 13:10:47 5667 [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'.                                      // 此句提示你默認mysql的root用戶隨機密碼存放於“/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                                     // 此句提示你mysql的配置文件位置“/usr/my.cnf”

will be used by default by the server when you start it.

You may edit this file to change server settings

[root@langer AtlassianResource]# rpm -ivh MySQL-client-5.6.26-1.el7.x86_64.rpm             // 執行安裝MySQL-client

Preparing...                ########################################### [100%]

   1:MySQL-client           ########################################### [100%]

[root@langer AtlassianResource]#                                                           // 安裝成功

下面爲MySQL RPM安裝方式文件分佈(有需要的可看看):

目錄

說明

/usr/bin

客戶端程序和可執行文件、腳本

/usr/sbin

服務端程序

/var/lib/mysql

日誌文件、數據庫文件  [重點要知道這個]

/usr/share/info

信息文件

/usr/share/man

聯機幫助文檔目錄

/usr/include/mysql

C頭文件目錄

/usr/lib/mysql

lib庫文件目錄

/usr/share/mysql

其他支持文件,包括錯誤信息,字符集文件,示例配置文件,SQL數據庫的安裝

/usr/share/sql-bench

基準程序

MySQL啓動與關閉命令:

[root@langer ~]# service mysql start                                                // 啓動命令

[root@langer ~]# service mysql stop                                                 // 停止命令

4、配置MySQL

MySQL安裝完畢後,我們還需要進行一些配置。這些配置是根據官方文檔以及個人經驗整理出來的,如不做這些配置,可能造成中文字符亂碼、大文件附件無法上傳、大插件無法安裝等問題。

  • 修改MySQL root用戶的默認密碼(不改的話,不能用root用戶創建新庫、查詢數據等)

[root@langer ~]# service mysql start                                                // 啓動MySQL

[root@langer ~]# cat /root/.mysql_secret                                            // 查看MySQL root用戶的默認隨機密碼

# The random password set for the root user at Tue Jan 20 13:10:43 2015 (local time): F76Wy1A4G9ZuLcaG

[root@langer ~]# mysqladmin -u root -pF76Wy1A4G9ZuLcaG password F76Wy1A4G9ZuLcaH    // 改密命令格式:mysqladmin -u 用戶名 -p原密碼 password 新密碼(注意-p後面不要有空格),本例將原密碼末尾字母G改成H。

Warning: Using a password on the command line interface can be insecure.            // 看到此句表明密碼已經修改成功

[root@langer ~]# mysql -u root -p                                                   // 用新密碼登錄看看

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 16

Server version: 5.6.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2014, 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> exit                                                                         // 退出MySQL

Bye

[root@langer ~]#

[root@langer ~]# rm -rf /root/.mysql_secret                                         // 這個文件可以刪除了,我們已經改密了,它已經沒有存在的價值了。(新密碼記得記錄保存好噢噢噢!)

  • 修改MySQL my.cnf配置文件

[root@langer ~]# service mysql stop                                                 // 先停止MySQL服務

[root@langer ~]# vi /usr/my.cnf                                                     // 編輯my.cnf配置文件,下文中標“[###]”的行爲添加或修改過的配置

# For advice on how to change settings please see

http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysql]                                                                             // [###]

default-character-set=utf8                                                          // [###]

[mysqld]

# 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

 

transaction-isolation = READ-COMMITTED                                              // [###]

max_allowed_packet=128M                                                             // [###]

innodb_log_file_size=512M                                                           // [###]

innodb_buffer_pool_size=512M                                                        // [###]

innodb_file_per_table=1                                                             // [###]

collation-server=utf8_bin                                                           // [###]

character-set-server=utf8                                                           // [###]

default-storage-engine=INNODB                                                       // [###]

 

performance_schema_max_table_instances=400                                          // [###] 此行和下面兩行配置,添加後,若MySQL無法啓動,則請刪除;若可正常啓動,則最好添加上。

table_definition_cache=400                                                          // [###]

table_open_cache=256                                                                // [###]

[root@langer mysql]# cd /var/lib/mysql/                                             // 進入這個目錄,ls下我們可看到兩個文件ib_logfile0和ib_logfile1

[root@langer mysql]# rm -rf ib_logfile*                                             // 刪除這兩個文件

[root@langer mysql]# service mysql start                                            // 重新啓動MySQL服務,後面看配置是否生效

[root@langer mysql]# mysql -u root -p                                               // 登錄MySQL

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 18848

Server version: 5.6.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2014, 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> show VARIABLES like '%max_allowed_packet%';                                  // 查看最大包限制大小

+--------------------------+------------+

| Variable_name            | Value      |

+--------------------------+------------+

| max_allowed_packet       | 134217728  |

| slave_max_allowed_packet | 1073741824 |

+--------------------------+------------+

2 rows in set (0.00 sec)

mysql> SHOW VARIABLES LIKE 'character%';                                            // 查看字符集變量

+--------------------------+----------------------------+

| Variable_name            | Value                      |

+--------------------------+----------------------------+

| character_set_client     | utf8                       |

| character_set_connection | utf8                       |

| character_set_database   | utf8                       |

| character_set_filesystem | binary                     |

| character_set_results    | utf8                       |

| character_set_server     | utf8                       |

| character_set_system     | utf8                       |

| character_sets_dir       | /usr/share/mysql/charsets/ |

+--------------------------+----------------------------+

8 rows in set (0.00 sec)

mysql>                                                                              // 看到上面這些配置,表示我們前面修改的配置已經生效了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章