Linux下MySQL資料庫安裝與配置

來源:互聯網
上載者:User

標籤:

1. 安裝MySQL資料庫先從MySQL官網下載MySQL,然後進入所下載的安裝檔案所在目錄,運行如下命令進行安裝,其中MySQL-server-community-5.1.56-1.rhel5.i386.rpm為剛剛下載的MySQL資料庫伺服器的rpm包,然後使用/etc/rc.d/init.d/mysqlrestart命令重啟MySQL服務: 
  1. [[email protected] ~]# rpm -ivh MySQL-server-community-5.1.56-1.rhel5.i386.rpm  
  2. [[email protected] ~]# /etc/rc.d/init.d/mysql restart  
  3. Shutting down MySQL..[確定]  
  4. Starting MySQL..[確定]  

2. 配置MySQL資料庫字元集

備忘:配置MySQL資料庫字元集的目的是方便的使用資料庫,無需在每次串連的時候都要臨時設定資料庫字元集的,個人不建議採用這種方法,真正的工程項目都應該在串連資料庫時臨時設定資料庫字元集,如此才便於系統的移植,而且又不會影響資料庫伺服器中的其他資料庫的使用!

安裝完成之後,需要配置MySQL的字元集配置,首先需要尋找MySQL的設定檔的位置,由於MySQL的設定檔名是以.cnf結尾的,因此可用如下命令進行尋找:

 
  1. [[email protected] ~]# find / -iname ‘*.cnf‘ -print  
  2. /usr/share/mysql/my-large.cnf  
  3. /usr/share/mysql/my-medium.cnf  
  4. /usr/share/mysql/my-innodb-heavy-4G.cnf  
  5. /usr/share/mysql/my-huge.cnf  
  6. /usr/share/mysql/my-small.cnf  
  7. /usr/share/doc/MySQL-server-community-5.1.56/my-large.cnf  
  8. /usr/share/doc/MySQL-server-community-5.1.56/my-medium.cnf  
  9. /usr/share/doc/MySQL-server-community-5.1.56/my-innodb-heavy-4G.cnf  
  10. /usr/share/doc/MySQL-server-community-5.1.56/my-huge.cnf  
  11. /usr/share/doc/MySQL-server-community-5.1.56/my-small.cnf  
  12. /etc/pki/tls/openssl.cnf  

輸入完命令“find / -iname ‘*.cnf‘-print”斷行符號後,螢幕便顯示搜尋到的MySQL設定檔,然後拷貝my-large.cnf、my-medium.cnf 、my-innodb-heavy-4G.cnf 、my-huge.cnf、my-small.cnf中任意的一個到/etc目錄下,並命名為my.cnf,其命令如下所示:

 
  1. [[email protected] ~]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf  
  2. [[email protected] ~]# vi /etc/my.cnf  

然後,使用vi編輯器修改/etc/my.cnf檔案,在[client]下添加: “default-character-set=gb2312”;在[mysqld]下添加:“default-character-set=gb2312”。如下所示:

 
  1. # The following options will be passed to all MySQL clients  
  2. [client]  
  3. default-character-set=gb2312  
  4. #password       = your_password  
  5. port            = 3306  
  6. socket          = /var/lib/mysql/mysql.sock  
  7.   
  8. # Here follows entries for some specific programs  
  9.   
  10. # The MySQL server  
  11. [mysqld]  
  12. default-character-set=gb2312  
  13. port            = 3306  
  14. socket          = /var/lib/mysql/mysql.sock  
  15. skip-locking  
  16. key_buffer_size = 16M  
  17. max_allowed_packet = 1M  
  18. table_open_cache = 64  
  19. sort_buffer_size = 512K  
  20. net_buffer_length = 8K  

按一下Esc鍵,輸入“:wq”後斷行符號儲存設定檔,輸入“/etc/rc.d/init.d/mysqlrestart”重啟MySQL服務,如下所示:

 
  1. [[email protected] ~]# /etc/rc.d/init.d/mysql restart  
  2. Shutting down MySQL..[確定]  
  3. Starting MySQL..[確定]  

最後,我們來驗證MySQL伺服器配置是否成功,首先登入MySQL,輸入“mysql –uroot -p”斷行符號,系統提示輸入密碼,登入成功後進入MySQL命令模式,如下所示:

 
  1. [[email protected] ~]# mysql -uroot -p  
  2. Enter password:   
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.  
  4. Your MySQL connection id is 2  
  5. Server version: 5.1.56-community-log MySQL Community Server (GPL)  
  6. Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.  
  7. Oracle is a registered trademark of Oracle Corporation and/or its  
  8. affiliates. Other names may be trademarks of their respective  
  9. owners.  
  10. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.  
  11. mysql>  

在MySQL命令模式下分別輸入“show variables like‘collation_%‘;”、“show variables like ‘character_set_%‘;”斷行符號後顯示字元集設定,如下所示:

 
  1. mysql> show variables like ‘collation_%‘;  
  2. +----------------------+-------------------+  
  3. | Variable_name        | Value             |  
  4. +----------------------+-------------------+  
  5. | collation_connection | gb2312_chinese_ci |  
  6. | collation_database   | gb2312_chinese_ci |  
  7. | collation_server     | gb2312_chinese_ci |  
  8. +----------------------+-------------------+  
  9. 3 rows in set (0.05 sec)  
  10. mysql> show variables like ‘character_set_%‘;  
  11. +--------------------------+----------------------------+  
  12. | Variable_name            | Value                      |  
  13. +--------------------------+----------------------------+  
  14. | character_set_client     | gb2312                     |  
  15. | character_set_connection | gb2312                     |  
  16. | character_set_database   | gb2312                     |  
  17. | character_set_filesystem | binary                     |  
  18. | character_set_results    | gb2312                     |  
  19. | character_set_server     | gb2312                     |  
  20. | character_set_system     | utf8                       |  
  21. | character_sets_dir       | /usr/share/mysql/charsets/ |  
  22. +--------------------------+----------------------------+  
  23. 8 rows in set (0.00 sec)  
  24. mysql>  

根據以上查詢結果可知我們設定的MySQL資料庫配置資訊已經生效,至此完成MySQL的伺服器的安裝與配置。

3.關於MySQL資料庫的一些注意事項3.1 遠端連線mysql速度慢解決方案:在MySQL伺服器的配置(/etc/my.cnf)中增加一個如下配置後速度飛快。 
  1. [mysqld]  
  2. skip-name-resolve  
 備忘:這樣就能禁用DNS解析,連線速度會快很多。不過,這樣的話就不能在MySQL的授權表中使用主機名稱了而只能用ip格式。
3.2 重啟資料庫後,發現無需密碼(或者任何密碼)即可以串連解決方案:檢查你的MySQL設定檔(/etc/my.cnf)中是不是多了一條語句:“skip-grant-tables”,刪除(注釋)該語句,重新設定MySQL密碼,再次重啟MySQL服務即可!備忘:若使用skip-grant-tables系統將對任何使用者的訪問不做任何存取控制,但可以用 mysqladmin flush-privileges或mysqladmin reload來開啟存取控制;預設情況是show databases語句對所有使用者開放,如果mysql伺服器沒有開遠程帳戶,就在/etc/my.cnf裡面加上skip-grant-tables。  

    部落格地址:http://blog.csdn.net/shuxiao9058

    原始作者:季亞

Linux下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.