mysql詳解安裝

來源:互聯網
上載者:User

標籤:x86_64   ack   yum倉庫   monitor   http   伺服器   partition   its   tar   

三種安裝方式

1 二進位  解壓就用

2 YUM/RPM   適用於很多台伺服器安裝,編譯好後,做成RPM包 適用於yum倉庫

3 編譯安裝     自定安裝,相當於自己DIY了。。。5.1安裝用make,5.5安裝要用cmake

 

 

安裝二進位詳解示範!!

顯示系統名、節點名稱、作業系統的發行版號、作業系統版本、運行系統的機器 識別碼。

[[email protected] ~]# uname -a
Linux sky-mysql 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

 

上傳或者下載二進位包(官網或者網上,有很多)

[[email protected] ~]# ll /home/sky00747/tools/

-rw-r--r--. 1 root root 186722932 Apr 2 2017 mysql-5.5.32-linux2.6-x86_64.tar.gz

 

解壓縮

[[email protected] tools]# tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz
[[email protected] tools]# ll
total 182352
drwxr-xr-x. 13 root root 4096 Oct 21 22:41 mysql-5.5.32-linux2.6-x86_64
-rw-r--r--. 1 root root 186722932 Apr 2 2017 mysql-5.5.32-linux2.6-x86_64.tar.gz

 

拷貝到你要放到的目錄下

[[email protected] tools]#mkdir /application/

[[email protected] tools]# cp  -R mysql-5.5.32-linux2.6-x86_64 /application/

[[email protected] tools]#ln -s mysql-5.5.32-linux2.6-x86_64/ ./mysql #建立一個軟串連

模板檔案

[[email protected] mysql]# cd support-files/

[[email protected] support-files]# ll
total 100
-rwxr-xr-x. 1 root root 1153 Oct 21 22:43 binary-configure
-rwxr-xr-x. 1 root root 4528 Oct 21 22:43 config.huge.ini
-rwxr-xr-x. 1 root root 2382 Oct 21 22:43 config.medium.ini
-rwxr-xr-x. 1 root root 1626 Oct 21 22:43 config.small.ini
-rw-r--r--. 1 root root 773 Oct 21 22:43 magic
-rw-r--r--. 1 root root 4691 Oct 21 22:43 my-huge.cnf
-rw-r--r--. 1 root root 19759 Oct 21 22:43 my-innodb-heavy-4G.cnf
-rw-r--r--. 1 root root 4665 Oct 21 22:43 my-large.cnf
-rw-r--r--. 1 root root 4676 Oct 21 22:43 my-medium.cnf
-rw-r--r--. 1 root root 2840 Oct 21 22:43 my-small.cnf
-rwxr-xr-x. 1 root root 1061 Oct 21 22:43 mysqld_multi.server
-rwxr-xr-x. 1 root root 839 Oct 21 22:43 mysql-log-rotate
-rwxr-xr-x. 1 root root 10880 Oct 21 22:43 mysql.server
-rwxr-xr-x. 1 root root 1326 Oct 21 22:43 ndb-config-2-node.ini
drwxr-xr-x. 2 root root 4096 Oct 21 22:43 solaris

 

建立存放data檔案的目錄

[[email protected] ~]# mkdir /var/lib/mysql

 

 

 

拷貝模板檔案(就是設定檔),根據自己需求拷貝把。也可以後慢慢改改

[[email protected] support-files]# cp my-large.cnf ./my.cnf

這樣拷貝會有很多的注釋。。根據自己喜好吧。。。我就不注釋了

注釋參數 cat my-large.cnf|egrep -v "#|^$" >/etc/my.cnf

 

vim my.cnf

在[mysqld]中

添加datadir = /var/lib/mysql

cp ./my.cnf /var/lib/mysql

#預設是可以拷貝到/etc/my.cnf

 

建立mysql使用者,但是不能讓這個使用者登入

[[email protected] support-files]# useradd mysql -s /sbin/nologin -M

將目錄授權給mysql使用者與組

[[email protected] support-files]# chown -R mysql.mysql /var/lib/mysql/
[[email protected] support-files]# ll /var/lib/mysql/
total 8
-rw-r--r--. 1 mysql mysql 4689 Oct 21 23:25 my.cnf

 

 

配置開機檔案

[[email protected] support-files]# cp mysql.server /etc/init.d/mysqld

 

初始化(就是生產mysql的表)

./scripts/mysql_install_db --defaults-file=/var/lib/mysql/my.cnf --user=mysql

 

啟動mysql

可以通過/etc/init.d/mysqld start

還有一種

[[email protected] mysql]# cd /application/mysql/bin/

[[email protected] mysql]#./bin/mysqld_safe &

如果my.cnf 在/etc/下,這樣啟動就可以。但是我們的設定檔在/var/lib/mysql/下,就要指定檔案了

[[email protected] mysql]#./bin/mysqld_safe --defaults-file=/var/lib/mysql/my.cnf &

查看是否啟動

 查看連接埠

[[email protected] bin]# ss -lntup |grep 3306
tcp LISTEN 0 50 *:3306 *:* users:(("mysqld",27975,11))

 

查看任務

[[email protected] bin]# ps -ef |grep mysqld
root 27697 27448 0 23:56 pts/0 00:00:00 /bin/sh ./mysqld_safe --defaults-file=/var/lib/mysql/my.cnf
mysql 27975 27697 1 23:56 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=/var/lib/mysql/my.cnf --basedir=/usr/local/mysql --datadir=/var/lib/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/var/lib/mysql/sky-mysql.err --pid-file=/var/lib/mysql/sky-mysql.pid --socket=/tmp/mysql.sock --port=3306

 

啟動mysql

[[email protected] bin]# echo ‘export PATH=/application/mysql/bin:$PATH‘ >> /etc/profile
[[email protected] bin]# tail -1 /etc/profile
export PATH=/application/mysql/bin:$PATH
[[email protected] bin]# source /etc/profile

加入環境變數就可直接啟動mysql了

[[email protected] bin]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.32-log MySQL Community Server (GPL)

Copyright (c) 2000, 2013, 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>

 

 

===============================編譯安裝=====================

 

安裝5.5

檢查依賴包

yum install ncurses-devel libaio-devel -y

rpm -qa ncurses-devel libaio

 

如果安裝5.5 需要一個軟體 cmake

https://cmake.org/files/v3.7/cmake-3.7.2.tar.gz

tar xf cmake-3.6.3.tar.gz

cd cmake-3.6.3.tar.gz

./configure

gmake

gmake install

==========安裝mysql===========

建立使用者

useradd mysql -s /sbin/nologin -M

 

cd mysql-5.5.32

編譯

cd mysql-5.5.32

編譯

cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.32 \

-DMYSQL_DATADIR=/application/mysql-5.5.32/data \

-DMYSQL_UNIX_ADDR=/application/mysql-5.5.32/tmp/mysql.sock \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \

-DENABLED_LOCAL_INFILE=ON \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_FEDERATED_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \

-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \

-DWITH_FAST_MUTEXES=1 \

-DWITH_ZLIB=bundled \

-DENABLED-LOCAL_INFILE=1 \

-DWITH_READLINE=1 \

-DWITH_EMBEDDED_SERVER=1 \

-DWITH_DEBUG=0

make && make install &

 

ln -s /application/mysql-5-5.32/ /application/mysql

 

安裝完成

 

拷貝模板

cp support-files/my-small.cnf /etc/my.cnf

cp: overwrite `/etc/my.cnf‘? y

 

配置環境變數

echo ‘export PATH=/application/mysql/bin:$PATH‘ >> /etc/profile

tail -1 /etc/profile

source /etc/profile

echo $PATH

/application/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

一定要排在最前面

 

chown -R mysql.mysql /application/mysql/data/

chmod -R 1777 /tmp/

 

初始化

cd /application/mysql/scripts/

./mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql

 

 

init.d啟動指令碼

cp support-files/mysql.server /etc/init.d/mysqld

chmod +x /etc/init.d/mysqld

/etc/init.d/mysqld start

 

查看連接埠

netstat -lntup|grep 3306

tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 19011/mysqld

 

就能登入了

 

啟動mysql

 

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.