標籤:mysq 二進位安裝軟體
二進位安裝 其實就是已經編譯好的mysql,做了個壓縮包,下載下來,解壓縮,簡單配置之後,就能使用,‘安裝’速度快,往往用於mysql的快速部署。
添加 mysql 使用者:
[[email protected] ~]# groupadd mysql[[email protected] ~]# useradd -s /sbin/nologin -g mysql -M mysql
-s /sbin/nologin 表示禁止該使用者登入系統,提高安全性
-g mysql 指定mysql 使用者屬於mysql組
-M 表示不建立使用者家目錄(這裡沒必要建立)
檢查剛剛建立的mysql使用者和組:
[[email protected] ~]# tail -1 /etc/passwdmysql:x:501:501::/home/mysql:/sbin/nologin[[email protected] ~]# id mysqluid=501(mysql) gid=501(mysql) groups=501(mysql)
擷取mysql軟體包:
在mysql官網 選Linux - Generic 本文用的包是 mysql-5.5.49-linux2.6-x86_64.tar.gz
平台是 centos6.4
http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.49-linux2.6-x86_64.tar.gz
5.5版本的mysql,空密碼,可直接登入
[[email protected] ~]# wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.49-linux2.6-x86_64.tar.gz # 擷取mysql軟體壓縮包[[email protected] ~]# tar xf mysql-5.5.49-linux2.6-x86_64.tar.gz # 解壓[[email protected] ~]# mv mysql-5.5.49-linux2.6-x86_64 /application/mysql-5.5.49# 移動到指定的安裝目錄,目錄標明了mysql的版本( 二進位安裝可以自訂安裝目錄 )[[email protected] ~]# ln -s /application/mysql-5.5.49/ /application/mysql# 建立軟連結 [[email protected] ~]# cd /application/mysql[[email protected] mysql]# lsbin data include lib mysql-test scripts sql-benchCOPYING docs INSTALL-BINARY man README share support-files
初始化 mysql 設定檔 my.cnf:
在support-file 下有 my.cnf 的各種配置範例,根據情況選擇設定檔。
[[email protected] mysql]# /bin/cp support-files/my-small.cnf /etc/my.cnf
初始化 mysql 資料庫檔案:
[[email protected] mysql]# mkdir -p /application/mysql/data # 建立mysql資料檔案目錄[[email protected] mysql]# chown -R mysql.mysql /application/mysql/ # 授權mysql使用者管理mysql的安裝目錄[[email protected] mysql]# /application/mysql/scripts/mysql_install_db \ # 初始化mysql資料庫檔案> --basedir=/application/mysql \ # 指定mysql目錄> --datadir=/application/mysql/data \ # 指定mysql資料檔案目錄> --user=mysql # 指定使用者# 初始化成功會有2個 OK ,如果有ERROR 錯誤,就要去解決,再初始化
注意:有些軟體包的 mysql_install_db 不在 scripts 目錄下 ,可能在 bin目錄下或其他目錄下
配置並啟動 mysql 資料庫:
[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld # 拷貝 mysql啟動指令碼到mysql 的命令路徑[[email protected] mysql]# chmod +x /etc/init.d/mysqld # 添加執行許可權[[email protected] mysql]# sed -i ‘s#/usr/local/mysql#/application/mysql#g‘ /application/mysql/bin/mysqld_safe /etc/init.d/mysqld# mysql 二進位預設安裝路徑是/usr/local/mysql,啟動指令碼裡是/usr/local/mysql的路徑都需要替換[[email protected] mysql]# /etc/init.d/mysqld startStarting MySQL... SUCCESS!
設定mysql開機自動啟動:
[[email protected] mysql]# chkconfig --add mysqld[[email protected] mysql]# chkconfig mysqld on[[email protected] mysql]# chkconfig --list mysqldmysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
登入mysql資料庫:
[[email protected] ~]# /application/mysql/bin/mysqlWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.5.49 MySQL Community Server (GPL)Copyright (c) 2000, 2016, 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>
這樣啟動太麻煩了,可配置mysql命令的全域使用路徑:
[[email protected] mysql]# echo ‘export PATH=/application/mysql/bin:$PATH‘ >> /etc/profile # 追加 ‘export PATH=/application/mysql/bin:$PATH‘到 /etc/profile[[email protected] mysql]# source /etc/profile # 使追加內容的生效 # 以上用途為定義mysql全域路徑,實現在任意路徑執行mysql命令 [[email protected] ~]# mysql # 直接進入mysqlWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.5.49 MySQL Community Server (GPL)Copyright (c) 2000, 2016, 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> ...[[email protected] ~]# mysql -uroot -p # 也可這樣登入,不需要使用密碼
設定 mysql 的 root密碼:
[[email protected] mysql]# mysqladmin -u root password ‘redhat‘[[email protected] mysql]# mysqlERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: NO)[[email protected] mysql]# mysql -uroot -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 6Server version: 5.5.49 MySQL Community Server (GPL)Copyright (c) 2000, 2016, 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>
比起官網的 rpm/yum 安裝,二進位安裝可以可更改安裝路徑,但本質上只是把已經編譯好的那過來用而已,如果你有什麼特殊的需要,並不能滿足。如果你有什麼特殊的需要則應該使用 源碼編譯安裝。
本文出自 “11417860” 部落格,請務必保留此出處http://11427860.blog.51cto.com/11417860/1770537
mysql 的二進位安裝