Ubuntu 14 下使用離線包安裝mysql

Ubuntu 14 下使用離線包安裝mysql

最近沒事想在Ubuntu上搞個mysql玩玩,本人最習慣使用的Linux系統是Ubuntu,但是發現,在mysql官網下載的老版本的(5.6之前)mysql沒有提供對Ubuntu的DEB安裝包(mysql看不起Ubuntu?),所以就不得不使用離線包進行安裝了,安裝過程中遇到了許多的問題,經過一番的摸索以及查詢一些資料,終於把mysql安裝成功了。下面我把我的安裝過程分享給大家,不足之處請指正。

首先從mysql官網上下載所需的離線包,我現在的版本是5.5.45,下載鏈接是
http://cdn.mysql.com/archives/mysql-5.5/mysql-5.5.45-linux2.6-x86_64.tar.gz

建議使用迅雷下載,瀏覽器下載或者直接wget下載速度不穩定,經常會有下載失敗的情況

  • 下載完之後,將tar包拷貝到/usr/loacl目錄下解壓縮:
    tar -zxvf mysql-5.5.45-linux2.6-x86_64.tar.gz
  • 重命名爲mysql:
    mv mysql-5.5.45-linux2.6-x86_64 mysql
  • 在安裝之前先安裝一個依賴包,mysql運行的時候會用到這個依賴包,否則運行不了:
    apt-get install libaio-dev
  • 依賴包安裝完之後就該安裝mysql了,在/usr/local/mysql目錄下運行命令(後同),:(注意輸出的文字,裏邊有修改root密碼和啓動mysql的命令)
    ./scripts/mysql_install_db --user=root
    Installing MySQL system tables...
    151015 14:11:15 [Note] ./bin/mysqld (mysqld 5.5.45) starting as process 10902 ...
    OK
    Filling help tables...
    151015 14:11:15 [Note] ./bin/mysqld (mysqld 5.5.45) starting as process 10908 ...
    OK

    To start mysqld at boot time you have to copy
    support-files/mysql.server to the right place for your system

    PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
    To do so, start the server, then issue the following commands:

    ./bin/mysqladmin -u root password 'new-password'
    ./bin/mysqladmin -u root -h qiuxiao-ubuntu password 'new-password'

    Alternatively you can run:
    ./bin/mysql_secure_installation

    which will also give you the option of removing the test
    databases and anonymous user created by default.  This is
    strongly recommended for production servers.

    See the manual for more instructions.

    You can start the MySQL daemon with:
    cd . ; ./bin/mysqld_safe &

    You can test the MySQL daemon with mysql-test-run.pl
    cd ./mysql-test ; perl mysql-test-run.pl

    Please report any problems at http://bugs.mysql.com/
  • 啓動mysql,指定root用戶:
    ./bin/mysqld_safe --user=root &
  • 設置root用戶密碼
    ./bin/mysqladmin -u root password '新密碼'
  • 重啓mysql:
    ./bin/mysqladmin -uroot -p密碼 shutdown(注意,u,p後沒有空格)
    ./bin/mysqld_safe --user=root &
  • 設置允許root遠程連接:
    1)本機登陸mysql:

    ./bin/mysql -u root -p

    2)從所有主機:

    mysql> grant all privileges on *.* to root@"%" identified by "root用戶的密碼" with grant option;

    3)從指定主機:

    mysql> grant all privileges on *.* to root@"192.168.11.205" identified by "root用戶的密碼" with grant option; flush privileges;
  • 設置字符集:
    查詢字符集:

    mysql> show variables like 'character%';

    字符集查詢結果

    mysql> SET character_set_database = utf8;
    mysql> SET character_set_server = utf8;

    重啓,使字符集生效

  • 設置開機啓動
    可以通過support-files下的mysql.server啓動停止mysql,命令如下:
    啓動mysql:./support-files/mysql.server start –user=root
    停止mysql:./support-files/mysql.server stop

    1)mysql啓動默認使用的是/etc/my.cnf配置文件,所以拷貝一份配置文件到/etc/下:

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

    2)拷貝mysql.server文件到/etc/init.d/目錄下:

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

    3)指定啓動時所使用的用戶,修改my.cnf配置文件,在[mysqld]下加一行user=root:

    vim /etc/my.cnf

    編輯my.cnf文件,增加啓動用戶
    4)設置開機啓動:

    update-rc.d -f mysql.server defaults

    設置開機啓動

至此,mysql安裝完畢,重啓Ubuntu,驗證一下mysql是否已經隨機啓動
重啓Ubuntu

Navicat連接mysql
Navicat連接mysql

連接成功

由圖可知,連接成功!
此處有掌聲

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章