Ubuntu 12.04下安裝MySQL圖解

來源:互聯網
上載者:User

標籤:變更   ace   使用者模式   top   title   repo   遠程登入   character   sel   

先下載好mysql的linux安裝包,從官網下,我下載的是5.6社區版, 下載後傳到ubuntu上去。

包放在~/download目錄下,全部安裝命令如下:

 

1、解壓tar.gz

tar –xzf  mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz

2、重新命名解壓的檔案夾

mv mysql-5.6.26-linux-glibc2.5-x86_64 mysql

3、將mysql檔案夾移動到/usr/local目錄下

sudo mv ~/download/mysql  /usr/local

4、進入mysql目錄

cd /usr/local/mysql

5、增加mysql使用者及組

sudo useradd -r  mysql

6、將mysql檔案夾own及grp變更為mysql

sudo chown -R mysql:mysql mysql/

7、執行mysql安裝指令碼

sudo scripts/mysql_install_db --user=mysql

(若未安裝libaio包,會有一個報錯提示,安裝libaio-dev後,再運行指令碼即可。如果還是出錯可以刪除rm -rf /etc/my.cnf)

sudo apt-get install libaio-dev

 

8、將目錄許可權變更回來,僅保留data目錄為mysql使用者

sudo chown -R root:root mysql .

sudo chown -R mysql:mysql  data

9、將mysql設定檔拷貝到etc目錄(全域配置)

注意:5.6版本的預設設定檔名稱由原先的my-medium變更為了my-default。

sudo cp support-files/my-default.cnf /etc/my.cnf

 

10、啟動mysql

sudo bin/mysqld_safe --user=mysql &

11、初始化mysql root使用者密碼

sudo bin/mysqladmin -u  root -p   ‘使用者自訂密碼‘;

#ps -A|grep mysql 
   顯示類似:
  1829 ?        00:00:00 mysqld_safe
   1876 ?        00:00:31 mysqld
  2.#kill -9 1829
  3.#kill -9 1876

 

12、複製mysql.server指令碼到/etc/init.d(初始化服務,有些人喜歡改成mysql,在這裡改就可以)

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

 

14、查看mysql運行狀態

sudo service mysql.server status
如果運行正常,會顯示 MySQL running。

如果顯示 not running,應該是前面沒有啟動服務,可直接用service mysql.server start啟動

sudo service mysql.server [status|start|stop] 

 

15、讓mysql開機啟動[defaults],取消開機啟動[remove]

sudo update-rc.d -f mysql.server defaults  [remove]

 

16、將mysql/bin/mysql命令加入到使用者命令中,或將mysql/bin目錄加入path

加入使用者命令:

sudo ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql

加入環境變數:

export PATH=$PATH:/usr/local/mysql/bin

 

17、允許root使用者遠程登入

1>進入mysql: mysql –u root –p

2>改變資料庫: use mysql;

3>從任意主機登入: grant all privileges on *.* to [email protected]"%" identified by "密碼文字" with grant option;

4>從指定主機登入: grant all privileges on *.* to [email protected]"192.168.1.101" identified by "passw0rd" with grant option;

5>授權生效: flush privileges;

6>查看host為%授權是否添加: select * from user;

7>查看資料庫字元集: show variables like ‘character%‘;

 

 

啟動完mysql後,我們接著可以測試一下,使用“mysql”命令來進入mysql資料庫的控制台
$mysql -u root

 

在這裡之所以用-u root是因為我現在是一般使用者(firehare),如果不加-u root的話,mysql會以為是firehare在登入。注意,我在這裡沒有進入根使用者模式,因為沒必要。一般來說,對mysql中的資料庫進行操作,根本沒必要進入根使用者模式,只有在設定時才有這種可能。

 

進入mysql之後,最要緊的就是要設定Mysql中的root使用者密碼了,否則,Mysql服務無安全可言了。
mysql> GRANT ALL PRIVILEGES ON *.* TO [email protected] IDENTIFIED BY "123456";
如果需要使用root從其他機器遠端存取可以使用
mysql> GRANT ALL PRIVILEGES ON *.* TO [email protected]“%” IDENTIFIED BY "123456";
注意,我這兒用的是123456做為root使用者的密碼,但是該密碼是不安全的,請大家最好使用大小寫字母與數字混合的密碼,且不少於8位。

 

 

設定檔參考:

 

[html] view plain copy  
  1. # For advice on how to change settings please see  
  2. # http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html  
  3. # *** DO NOT EDIT THIS FILE. It‘s a template which will be copied to the  
  4. # *** default location during install, and will be replaced if you  
  5. # *** upgrade to a newer version of MySQL.  
  6.   
  7. [client]  
  8. port        = 3306  
  9. default-character-set=utf8  
  10. # Here is entries for some specific programs  
  11. # The following values assume you have at least 32M ram  
  12.   
  13. [mysqld]  
  14. character_set_server=utf8  
  15. lower_case_table_names=1  
  16. init_connect=‘SET NAMES utf8‘  
  17.   
  18. lower_case_table_names=1  
  19.   
  20. max_connections=3000    
  21. max_allowed_packet = 32M   
  22.   
  23. thread_cache_size = 16    
  24. thread_concurrency = 8    
  25.   
  26. query_cache_size = 128M    
  27.   
  28. # Remove leading # and set to the amount of RAM for the most important data  
  29. # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.  
  30. # innodb_buffer_pool_size = 128M  
  31.   
  32. # Remove leading # to turn on a very important data integrity option: logging  
  33. # changes to the binary log between backups.  
  34. # log_bin  
  35.   
  36. # These are commonly set, remove the # and set as required.  
  37. # basedir = .....  
  38. # datadir = .....  
  39. # port = .....  
  40. # server_id = .....  
  41. # socket = .....  
  42.   
  43. # Remove leading # to set options mainly useful for reporting servers.  
  44. # The server defaults are faster for transactions and fast SELECTs.  
  45. # Adjust sizes as needed, experiment to find the optimal values.  
  46.  join_buffer_size = 16M  
  47.  sort_buffer_size = 16M  
  48. # read_rnd_buffer_size = 2M   
  49.   
  50. sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES   
  51.   
  52. [mysqldump]  
  53. quick  
  54. quote-names  
  55. max_allowed_packet = 32M    
  56.     
  57. [mysql]    
  58. no-auto-rehash    

 

 

參考文章: http://blog.csdn.net/njchenyi/article/details/17615391

Ubuntu 12.04下安裝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.