CentOS-minimal 6.5 安裝mysql

CentOS-minimal 6.5 安裝mysql

之前寫了一個在Ubuntu上使用離線包安裝mysql的過程,相較於CentOS來說稍微麻煩點,因爲mysql提供了rpm安裝包。

在安裝之前,我們先把所需的安裝包下載下來,使用的版本還是5.5.45,與Ubuntu離線包的區別是,這裏我們要下載三個安裝包,下載鏈接如下:

http://cdn.mysql.com/archives/mysql-5.5/MySQL-server-5.5.45-1.linux2.6.x86_64.rpm

http://cdn.mysql.com/archives/mysql-5.5/MySQL-client-5.5.45-1.linux2.6.x86_64.rpm

http://cdn.mysql.com/archives/mysql-5.5/MySQL-devel-5.5.45-1.linux2.6.x86_64.rpm

這裏還是建議使用迅雷下載,下載完成後待用。

  • 首先,我使用的CentOS是minimal6.5版本的,查看是否安裝了mysql:
    [root@qiuxiao ~]# rpm -qa | grep mysql
    mysql-libs-5.1.71-1.el6.x86_64
  • 此版本默認安裝了mysql-libs(其他版本我也看過了,安裝的更多),先把它卸載掉,否則後面安裝不了:
    [root@qiuxiao ~]# rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64
  • 在安裝之前先安裝一個依賴包,mysql運行的時候會用到這個依賴包,否則運行不了:
    [root@qiuxiao ~]# yum install libaio
  • 安裝mysql,安裝順序如下(別忘了先上傳到CentOS上,我是上傳到/usr/local/目錄下),注意輸出的信息,會用到的:
    [root@qiuxiao local]# rpm -ivh MySQL-server-5.5.45-1.linux2.6.x86_64.rpm
    warning: MySQL-server-5.5.45-1.linux2.6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Preparing...                ########################################### [100%]
       1:MySQL-server           ########################################### [100%]
    151020 19:14:16 [Note] /usr/sbin/mysqld (mysqld 5.5.45) starting as process 1240 ...
    151020 19:14:16 [Note] /usr/sbin/mysqld (mysqld 5.5.45) starting as process 1247 ...

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

    /usr/bin/mysqladmin -u root password 'new-password'
    /usr/bin/mysqladmin -u root -h qiuxiao password 'new-password'

    Alternatively you can run:
    /usr/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.

    Please report any problems at http://bugs.mysql.com/

    [root@qiuxiao local]# rpm -ivh MySQL-client-5.5.45-1.linux2.6.x86_64.rpm
    warning: MySQL-client-5.5.45-1.linux2.6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Preparing...                ########################################### [100%]
       1:MySQL-client           ########################################### [100%]

    [root@qiuxiao local]# rpm -ivh MySQL-devel-5.5.45-1.linux2.6.x86_64.rpm
    warning: MySQL-devel-5.5.45-1.linux2.6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Preparing...                ########################################### [100%]
       1:MySQL-devel            ########################################### [100%]
  • 啓動mysql服務:
    [root@qiuxiao local]# service mysql start
    Starting MySQL.. SUCCESS!
  • 修改root密碼:
    [root@qiuxiao local]# /usr/bin/mysqladmin -u root password 'new password'
  • 登錄mysql:

    [root@qiuxiao local]# mysql -u root -p
    Enter password: 
  • 設置字符集
    1)查詢字符集:

    mysql> show variables like'character%';

    查詢字符集

    2)修改字符集:

    mysql> SET character_set_database = utf8;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> SET character_set_server = utf8;
    Query OK, 0 rows affected (0.00 sec)
  • 設置root用戶可以遠程連接(以下兩種任選其一)
    1)從所有主機:

    mysql> grant all privileges on *.* to root@"%" identified by"root用戶的密碼"with grant option;
    Query OK, 0 rows affected (0.00 sec)

    2)從指定主機:

    mysql> grant all privileges on *.* to root@"192.168.11.205" identified by"root用戶的密碼"with grant option; flush privileges;
    Query OK, 0 rows affected (0.00 sec)
  • 重啓mysql服務

    [root@qiuxiao ~]# service mysql restart
    Shutting down MySQL... SUCCESS! 
    Starting MySQL.. SUCCESS!
  • 防火牆開放mysql端口3306
    1)開放3306端口:

    [root@qiuxiao ~]# /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT

    2)保存:

    [root@qiuxiao ~]# /etc/rc.d/init.d/iptables save
    iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]

    3)重啓防火牆:

    [root@qiuxiao ~]# /etc/init.d/iptables restart
    iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
    iptables: Flushing firewall rules:                         [  OK  ]
    iptables: Unloading modules:                               [  OK  ]
    iptables: Applying firewall rules:                         [  OK  ]
  • Navicat連接mysql
    Nacicat連接mysql

連接成功

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

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