Linux作業系統下MySQL的安裝 --轉

來源:互聯網
上載者:User

標籤:engine   not   ica   技術   sed   壓縮   lock   class   default   

轉自:http://www.cnblogs.com/mjorcen/p/4000371.html

 

註:另外的網址參考:http://www.linuxidc.com/Linux/2015-01/112583.htm

 

在Linux作業系統下,安裝MYSQL有兩種方式:

  一種tar安裝方式,

  另外一種是rpm安裝方式。

  這兩種安裝方式有什麼區別呢?儘管我們在Linux下常用tar來壓縮/解壓縮檔案,但MYSQL的tar格式的檔案其實只是mysql的檔案包,並不能直接安裝,需要操作configure、make、install等命令才能完成安裝,是一種比較繁瑣的安裝方式。而rpm格式的檔案是真正的安裝包,相當於windows的exe檔案,可以直接安裝。

  

  本文以MySQL-5.6.21 64位版本rpm格式的安裝方式為例,詳述MySQL的安裝方式,32位的rpm版本安裝方式也是如此。

(一)刪除老版本的MySQL

  在安裝前要先確定系統是否已經安裝了其他版本的MySQL,如已安裝其他版本的MySQL,需先刪除後再安裝新版本。經本文親測,採用如下方式刪除老版本的MySQL或MySQL殘留檔案作為方便。

  1. 執行yum命令,刪除MySQL的lib庫,服務檔案

yum remove mysql mysql-server mysql-libs mysql-server;

  2. 執行find命令,尋找MySQL的殘留檔案,然後運行“rm -rf 檔案名稱”刪除殘留的MySQL檔案

find / -name mysql

 

(二)RPM格式安裝MySQL 

  當前,MySQL的最新版本為:5.6.21,從官網下載MySQL的rpm安裝包,解壓後有如下六個檔案:

 

  1. MySQL-client-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL用戶端程式
  2. MySQL-devel-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL的庫和標頭檔
  3. MySQL-embedded-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL的嵌入式程式
  4. MySQL-server-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL服務端程式
  5. MySQL-shared-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL的共用庫
  6. MySQL-test-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL的測試組件

  一般對於開發而言,我們只需要下面三個檔案就可以。

  1. MySQL-devel-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL的庫和標頭檔
  2. MySQL-server-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL服務端程式 
  3. MySQL-devel-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL的庫和標頭檔
1. 在重新進行安裝之前,為確保萬無一失,我們還是再確認一下系統中是否有MySQL極其相關的RPM安裝包。如果有,則先刪除。
rpm -qa | grep -i mysql

執行完上述命令後,返回空資料,則可進行第二步。否則,執行下面的命令刪除MySQL的相關包檔案。

yum -y remove mysql-libs*
2. 將前面提到的三個MySQL安裝檔案,拷貝到伺服器,然後執行下述安裝命令
rpm -ivh MySQL-server-5.6.21-1.linux_glibc2.5.x86_64.rpmrpm -ivh MySQL-devel-5.6.21-1.linux_glibc2.5.x86_64.rpmrpm -ivh MySQL-client-5.6.21-1.linux_glibc2.5.x86_64.rpm

debug 如下:

[[email protected]_32_234_centos tools]# rpm -ivh MySQL-server-5.6.21-1.linux_glibc2.5.x86_64.rpmPreparing...                ########################################### [100%]   1:MySQL-server           rpm -ivh MySQL-devel-5.6.21-1.linux_glibc2.5.x86_64.rpmrpm -ivh MySQL-client-5.6.21-1.linux_glibc2.5.x86_64.rpm#################       ########################################### [100%]2014-09-29 15:01:50 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2014-09-29 15:01:50 30994 [Note] InnoDB: Using atomics to ref count buffer pool pages2014-09-29 15:01:50 30994 [Note] InnoDB: The InnoDB memory heap is disabled2014-09-29 15:01:50 30994 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2014-09-29 15:01:50 30994 [Note] InnoDB: Memory barrier is not used2014-09-29 15:01:50 30994 [Note] InnoDB: Compressed tables use zlib 1.2.32014-09-29 15:01:50 30994 [Note] InnoDB: Using Linux native AIO2014-09-29 15:01:50 30994 [Note] InnoDB: Using CPU crc32 instructions2014-09-29 15:01:50 30994 [Note] InnoDB: Initializing buffer pool, size = 128.0M2014-09-29 15:01:50 30994 [Note] InnoDB: Completed initialization of buffer pool2014-09-29 15:01:50 30994 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!2014-09-29 15:01:50 30994 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB2014-09-29 15:01:50 30994 [Note] InnoDB: Database physically writes the file full: wait...2014-09-29 15:01:51 30994 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB2014-09-29 15:01:52 30994 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB2014-09-29 15:01:52 30994 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile02014-09-29 15:01:52 30994 [Warning] InnoDB: New log files created, LSN=457812014-09-29 15:01:52 30994 [Note] InnoDB: Doublewrite buffer not found: creating new2014-09-29 15:01:52 30994 [Note] InnoDB: Doublewrite buffer created2014-09-29 15:01:52 30994 [Note] InnoDB: 128 rollback segment(s) are active.2014-09-29 15:01:52 30994 [Warning] InnoDB: Creating foreign key constraint system tables.2014-09-29 15:01:52 30994 [Note] InnoDB: Foreign key constraint system tables created2014-09-29 15:01:52 30994 [Note] InnoDB: Creating tablespace and datafile system tables.2014-09-29 15:01:52 30994 [Note] InnoDB: Tablespace and datafile system tables created.2014-09-29 15:01:52 30994 [Note] InnoDB: Waiting for purge to start2014-09-29 15:01:52 30994 [Note] InnoDB: 5.6.21 started; log sequence number 0A random root password has been set. You will find it in ‘/root/.mysql_secret‘.2014-09-29 15:01:53 30994 [Note] Binlog end2014-09-29 15:01:53 30994 [Note] InnoDB: FTS optimize thread exiting.2014-09-29 15:01:53 30994 [Note] InnoDB: Starting shutdown...2014-09-29 15:01:54 30994 [Note] InnoDB: Shutdown completed; log sequence number 16259772014-09-29 15:01:54 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).2014-09-29 15:01:54 31016 [Note] InnoDB: Using atomics to ref count buffer pool pages2014-09-29 15:01:54 31016 [Note] InnoDB: The InnoDB memory heap is disabled2014-09-29 15:01:54 31016 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins2014-09-29 15:01:54 31016 [Note] InnoDB: Memory barrier is not used2014-09-29 15:01:54 31016 [Note] InnoDB: Compressed tables use zlib 1.2.32014-09-29 15:01:54 31016 [Note] InnoDB: Using Linux native AIO2014-09-29 15:01:54 31016 [Note] InnoDB: Using CPU crc32 instructions2014-09-29 15:01:54 31016 [Note] InnoDB: Initializing buffer pool, size = 128.0M2014-09-29 15:01:54 31016 [Note] InnoDB: Completed initialization of buffer pool2014-09-29 15:01:54 31016 [Note] InnoDB: Highest supported file format is Barracuda.2014-09-29 15:01:54 31016 [Note] InnoDB: 128 rollback segment(s) are active.2014-09-29 15:01:54 31016 [Note] InnoDB: Waiting for purge to start2014-09-29 15:01:54 31016 [Note] InnoDB: 5.6.21 started; log sequence number 16259772014-09-29 15:01:54 31016 [Note] Binlog end2014-09-29 15:01:54 31016 [Note] InnoDB: FTS optimize thread exiting.2014-09-29 15:01:54 31016 [Note] InnoDB: Starting shutdown...2014-09-29 15:01:56 31016 [Note] InnoDB: Shutdown completed; log sequence number 1625987A 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_installationwhich 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.comSupport MySQL by buying support/licenses at http://shop.mysql.comNew default config file was created as /usr/my.cnf andwill be used by default by the server when you start it.You may edit this file to change server settings[[email protected]_32_234_centos tools]# rpm -ivh MySQL-devel-5.6.21-1.linux_glibc2.5.x86_64.rpmPreparing...                ########################################### [100%]   1:MySQL-devel            ########################################### [100%][[email protected]_32_234_centos tools]# rpm -ivh MySQL-client-5.6.21-1.linux_glibc2.5.x86_64.rpmPreparing...                ########################################### [100%]   1:MySQL-client           ########################################### [100%][[email protected]_32_234_centos tools]# 

  上述三個命令在執行時,只有第一個命令執行的時間稍微長些,後面兩個命令運行速度很快。 

 

3.執行下述命令,將MySQL的設定檔拷貝到/etc目錄下。
cp /usr/share/mysql/my-default.cnf /etc/my.cnf
4.分別運行下述命令,初始化MySQL及設定密碼。
/usr/bin/mysql_install_db    #初始化MySQL service mysql start        #啟動MySQL cat /root/.mysql_secret        #查看root帳號的初始密碼,會出現下述所示資訊

如:

[[email protected]_32_234_centos storage]# service mysql startStarting MySQL. SUCCESS! [[email protected]_32_234_centos storage]# cat /root/.mysql_secret# The random password set for the root user at Mon Sep 29 15:01:52 2014 (local time): PENFgcgkI8UnIKaE

[[email protected]_32_234_centos storage]# mysql -u root -pPENFgcgkI8UnIKaEWarning: Using a password on the command line interface can be insecure.Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 4Server version: 5.6.21Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql> 

   -- set password=password(‘123456‘); #更改MySQL密碼, 

mysql> set password=password(‘123456‘);Query OK, 0 rows affected (0.00 sec)
5.設定開機啟動
chkconfig mysql on
[[email protected]_32_234_centos storage]# chkconfig mysql on [[email protected]_32_234_centos storage]# chkconfig --list | grep mysqlmysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off

 上面列印出來的內容中,2~5為on就是開機啟動了。

6.修改/etc/my.cnf 

  設定MySQL的字元集,配置MySQL表明不區分大小寫(預設情況下,MySQL對錶名區分大小寫,列名不區分大小寫)。在[mysqld]下面加入如下內容:

 

character_set_server=utf8 character_set_client=utf8 collation-server=utf8_general_ci lower_case_table_names=1 max_connections=1000

 

7.MySQL的預設檔案路徑

 

  1. /var/lib/mysql/ #資料庫目錄
  2. /usr/share/mysql #設定檔目錄
  3. /usr/bin #相關命令目錄 #啟動指令碼

 

8.修改資料檔案路徑

  1.修改 /etc/my.cnf 檔案

   vi /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]# 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 = /storage/server/mysql-5.6.21-1/datadir = /storage/server/mysql-5.6.21-1/dataport = 3306server_id = 2socket = /storage/server/mysql-5.6.21-1/data/mysql.sockpid-file =/storage/server/mysql-5.6.21-1/data/VM_32_234_centos.pid# 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 = 2Msql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

 

複製檔案 /var/lib/mysql/  到 /storage/server/mysql-5.6.21-1/data/

 

cp -R /var/lib/mysql/* /storage/server/mysql-5.6.21-1/data/

 

9.重啟MySQL
# service mysql restart Shutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS!

 

Linux作業系統下MySQL的安裝 --轉

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.