一種tar安裝方式,
另外一種是rpm安裝方式。
這兩種安裝方式有什么區(qū)別呢?盡管我們?cè)贚inux下常用tar來(lái)壓縮/解壓縮文件,但MYSQL的tar格式的文件其實(shí)只是mysql的文件包,并不能直接安裝,需要操作configure、make、install等命令才能完成安裝,是一種比較繁瑣的安裝方式。而rpm格式的文件是真正的安裝包,相當(dāng)于windows的exe文件,可以直接安裝。
本文以MySQL-5.6.21 64位版本rpm格式的安裝方式為例,詳述MySQL的安裝方式,32位的rpm版本安裝方式也是如此。
在安裝前要先確定系統(tǒng)是否已經(jīng)安裝了其他版本的MySQL,如已安裝其他版本的MySQL,需先刪除后再安裝新版本。經(jīng)本文親測(cè),采用如下方式刪除老版本的MySQL或MySQL殘留文件作為方便。
1. 執(zhí)行yum命令,刪除MySQL的lib庫(kù),服務(wù)文件
yum remove mysql mysql-server mysql-libs mysql-server;2. 執(zhí)行find命令,查找MySQL的殘留文件,然后運(yùn)行“rm -rf 文件名”刪除殘留的MySQL文件
find / -name mysql(二)RPM格式安裝MySQL
當(dāng)前,MySQL的最新版本為:5.6.21,從官網(wǎng)下載MySQL的rpm安裝包,解壓后有如下六個(gè)文件:
MySQL-client-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL客戶端程序MySQL-devel-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL的庫(kù)和頭文件MySQL-embedded-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL的嵌入式程序MySQL-server-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL服務(wù)端程序MySQL-shared-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL的共享庫(kù)MySQL-test-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL的測(cè)試組件一般對(duì)于開發(fā)而言,我們只需要下面三個(gè)文件就可以。
MySQL-devel-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL的庫(kù)和頭文件MySQL-server-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL服務(wù)端程序 MySQL-devel-5.6.21-1.linux_glibc2.5.x86_64.rpm #MySQL的庫(kù)和頭文件1. 在重新進(jìn)行安裝之前,為確保萬(wàn)無(wú)一失,我們還是再確認(rèn)一下系統(tǒng)中是否有MySQL極其相關(guān)的RPM安裝包。如果有,則先刪除。
rpm -qa | grep -i mysql執(zhí)行完上述命令后,返回空數(shù)據(jù),則可進(jìn)行第二步。否則,執(zhí)行下面的命令刪除MySQL的相關(guān)包文件。
yum -y remove mysql-libs*2. 將前面提到的三個(gè)MySQL安裝文件,拷貝到服務(wù)器,然后執(zhí)行下述安裝命令
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.rpmdebug 如下:
[root@VM_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[root@VM_32_234_centos tools]# rpm -ivh MySQL-devel-5.6.21-1.linux_glibc2.5.x86_64.rpmPreparing... ########################################### [100%] 1:MySQL-devel ########################################### [100%][root@VM_32_234_centos tools]# rpm -ivh MySQL-client-5.6.21-1.linux_glibc2.5.x86_64.rpmPreparing... ########################################### [100%] 1:MySQL-client ########################################### [100%][root@VM_32_234_centos tools]#上述三個(gè)命令在執(zhí)行時(shí),只有第一個(gè)命令執(zhí)行的時(shí)間稍微長(zhǎng)些,后面兩個(gè)命令運(yùn)行速度很快。
3.執(zhí)行下述命令,將MySQL的配置文件拷貝到/etc目錄下。
cp /usr/share/mysql/my-default.cnf /etc/my.cnf4.分別運(yùn)行下述命令,初始化MySQL及設(shè)置密碼。
/usr/bin/mysql_install_db #初始化MySQL service mysql start #啟動(dòng)MySQL cat /root/.mysql_secret #查看root賬號(hào)的初始密碼,會(huì)出現(xiàn)下述所示信息如:
[root@VM_32_234_centos storage]# service mysql startStarting MySQL. SUCCESS! [root@VM_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[root@VM_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.設(shè)置開機(jī)啟動(dòng)
chkconfig mysql on[root@VM_32_234_centos storage]# chkconfig mysql on [root@VM_32_234_centos storage]# chkconfig --list | grep mysqlmysql 0:off 1:off 2:on 3:on 4:on 5:on 6:off上面打印出來(lái)的內(nèi)容中,2~5為on就是開機(jī)啟動(dòng)了。
6.修改/etc/my.cnf
設(shè)置MySQL的字符集,配置MySQL表明不區(qū)分大小寫(默認(rèn)情況下,MySQL對(duì)表名區(qū)分大小寫,列名不區(qū)分大小寫)。在[mysqld]下面加入如下內(nèi)容:
character_set_server=utf8 character_set_client=utf8 collation-server=utf8_general_ci lower_case_table_names=1 max_connections=10007.MySQL的默認(rèn)文件路徑
/var/lib/mysql/ #數(shù)據(jù)庫(kù)目錄/usr/share/mysql #配置文件目錄/usr/bin #相關(guān)命令目錄 #啟動(dòng)腳本8.修改數(shù)據(jù)文件路徑
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復(fù)制文件 /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!
新聞熱點(diǎn)
疑難解答
圖片精選