linux mysql安裝

想寫點什麼,怕本身哪天給忘了html

寫centos下的mysql安裝吧mysql

1、yum安裝(路徑都是rpm安裝時默認的路徑)linux

使用yum安裝c++

  • 安裝mysql客戶端:
    yum install mysqlsql

  • 安裝mysql 服務器端:
    yum install mysql-server
    yum install mysql-devel數據庫

有點windows下軟件安裝的感受,比較簡便。bootstrap

本身習慣了之前服務器數據庫存放路徑爲/data/mysql,套接字/tmp/mysql.sockwindows

經過yum安裝,數據庫存放路徑/var/lib/mysql,終究感受不是那麼習慣。centos

 

2、選擇源碼編譯安裝bash

1.下載mysql源碼安裝包
地址:http://www.mysql.com/downloads/mysql/5.5.html#downloads,我選擇了mysql-5.5.28-linux2.6-x86_64.tar.gz 

2.環境的配置
下載到服務器上後,會發現多了幾個cmake文件,已經取代了以前的configure檢查安裝。因此環境中須要安裝cmake包,固然gcc等關鍵安裝包是必須的。

   1.安裝cmake

           下載cmake#wget http://www.cmake.org/files/v2.8/cmake-2.8.3.tar.gz

           安裝gcc,gcc-c++

           #yum -y install gcc 
           #yum -y install gcc-c++

           配置編譯cmake

            #tar xvf cmake-2.8.3.tar.gz
           #cd cmake-2.8.3
           #./bootstrap
           #gmake
           #gmake install

   2.安裝mysql

           1.下載mysql,所下載包爲mysql-5.5.28-linux2.6-x86_64.tar.gz 
           2.添加必要的組和擁有者

              #/usr/sbin/groupadd mysql

              #/usr/sbin/useradd -g mysql mysql

              #mkdir /data/mysql

              #chown -R mysql:mysql /data/mysql

     3.編譯安裝

               # tar zxvf mysql-5.5.28-linux2.6-x86_64.tar.gz 
               # cd mysql-5.5.28-linux2.6-x86_64.tar.gz 
               #cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql   \

                   -DMYSQL_UNIX_ADDR=/tmp/mysql.sock  \

                   -DDEFAULT_CHARSET=utf8 \

                   -DDEFAULT_COLLATION=utf8_general_ci \

                   -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \

                   -DWITH_MYISAM_STORAGE_ENGINE=1 \

                   -DWITH_INNOBASE_STORAGE_ENGINE=1 \

                   -DWITH_MEMORY_STORAGE_ENGINE=1 \

                   -DWITH_READLINE=1 \

                   -DENABLED_LOCAL_INFILE=1 \

                   -DMYSQL_DATADIR=/data/mysql \

                   -DMYSQL_USER=mysql \

                   -DMYSQL_TCP_PORT=3306

           #make & make install

           #chmod +w /usr/local/mysql

           #chmod +w mysql:mysql /usr/local/mysql

           #cd /usr/local/mysql

           # cd support-files/
           # cp my-large.cnf /etc/my.cnf
           # cp mysql.server /etc/init.d/mysqld

       4.以mysql用戶帳戶的身份初始化DB

       5.配置my.cnf

後續等等按照本身經常使用的操做來

安裝方式分爲rpm和源碼編譯安裝兩種,本文是採用mysql源碼編譯方式,編譯器使用Cmake。軟件須要mysql-5.5.29.tar.gz和cmake-2.8.10.2.tar.gz,請自行下載。
下載地址:
http://mysql.mirror.kangaroot.net/Downloads/
http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz
其中mysql使用最新的穩定版本,即最新試用版的上一個版本,且非rc或者alpha的版本,Cmake直接用的最新版。

1.上傳mysql-5.5.29.tar.gz和cmake-2.8.10.2.tar.gz到/usr/local文件夾下。

2.CentOS安裝g++和ncurses-devel

[root@localhost local]# yum install gcc-c++
[root@localhost local]# yum install ncurses-devel

3.cmake的安裝

[root@localhost]# tar -zxv -f cmake-2.8.10.2.tar.gz // 解壓壓縮包
[root@localhost local]# cd cmake-2.8.10.2
[root@localhost cmake-2.8.10.2]# ./configure
[root@localhost cmake-2.8.10.2]# make
[root@localhost cmake-2.8.10.2]# make install

4.將cmake永久加入系統環境變量

用vi在文件/etc/profile文件中增長變量,使其永久有效,
[root@localhost local]# vi /etc/profile

在文件末尾追加如下兩行代碼:
PATH=/usr/local/cmake-2.8.10.2/bin:$PATH
export PATH

執行如下代碼使剛纔的修改生效:
[root@localhost local]# source /etc/profile

用 export 命令查看PATH值
[root@localhost local]# echo $PATH

5.建立mysql的安裝目錄及數據庫存放目錄

[root@localhost]# mkdir -p /usr/local/mysql //安裝mysql
[root@localhost]# mkdir -p /usr/local/mysql/data //存放數據庫

6.建立mysql用戶及用戶組

[root@localhost] groupadd mysql
[root@localhost] useradd -r -g mysql mysql

7.編譯安裝mysql

[root@localhost local]# tar -zxv -f mysql-5.5.29.tar.gz //解壓
[root@localhost local]# cd mysql-5.5.29
[root@localhost mysql-5.5.29]#
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_USER=mysql \
-DMYSQL_TCP_PORT=3306
[root@localhost mysql-5.5.29]# make
[root@localhost mysql-5.5.29]# make install

8.檢驗是否安裝成功

[root@localhost mysql-5.5.29]# cd /usr/local/mysql/
[root@localhost mysql]# ls
bin COPYING data docs include INSTALL-BINARY lib man mysql-test README scripts share sql-bench support-files
有bin等以上文件的話,恭喜你已經成功安裝了mysql。

配置mysql

9.設置mysql目錄權限

[root@localhost mysql]# cd /usr/local/mysql //把當前目錄中全部文件的全部者設爲root,所屬組爲mysql
[root@localhost mysql]# chown -R root:mysql .
[root@localhost mysql]# chown -R mysql:mysql data

10.將mysql的啓動服務添加到系統服務中

[root@localhost mysql]# cp support-files/my-medium.cnf /etc/my.cnf
cp:是否覆蓋"/etc/my.cnf"? y

11.建立系統數據庫的表

[root@localhost mysql]# cd /usr/local/mysql
[root@localhost mysql]# scripts/mysql_install_db --user=mysql

12.設置環境變量

[root@localhost ~]# vi /root/.bash_profile
在修改PATH=$PATH:$HOME/bin爲:
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib
[root@localhost ~]# source /root/.bash_profile //使剛纔的修改生效

13.手動啓動mysql

[root@localhost ~]# cd /usr/local/mysql
[root@localhost mysql]# ./bin/mysqld_safe --user=mysql & //啓動MySQL,但不能中止
mysqladmin -u root -p shutdown //此時root還沒密碼,因此爲空值,提示輸入密碼時,直接回車便可。

14.將mysql的啓動服務添加到系統服務中

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysql

15.啓動mysql

[root@localhost mysql]# service mysql start
Starting MySQL... ERROR! The server quit without updating PID file (/usr/local/mysql/data/localhost.localdomain.pid).

啓動失敗:
我這裏是權限問題,先改變權限
[root@localhost mysql]# chown -R mysql:mysql /usr/local/mysql

接着啓動服務器
[root@localhost mysql]# /etc/init.d/mysql start

16.修改MySQL的root用戶的密碼以及打開遠程鏈接

[root@localhost mysql]# mysql -u root mysql

mysql> use mysql;
mysql> desc user;
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root"; //爲root添加遠程鏈接的能力
mysql> update user set Password = password('123456') where User='root'; //設置root用戶密碼
mysql> select Host,User,Password from user where User='root';
mysql> flush privileges;
mysql> exit

17.從新登陸

[root@localhost mysql]# mysql -u root -p
Enter password:123456

若還不能進行遠程鏈接,關閉防火牆[root@localhost]# /etc/rc.d/init.d/iptables stop

相關文章
相關標籤/搜索