一、首先到mysql的下載中心上下載最新的tar.gz包,網站:http://www.mysql.com/downloads/ mysql
二、下載後獲得文件MySQL-5.5_mysql-5.5.34-linux2.6-i686.tar.gz,而後將其解壓,並重命名爲mysql,使用mv命令將其移到/usr/local目錄下 linux
1 |
sudo mv ~/下載/mysql /usr/local |
提示:其中文本文件INSTALL-BINARY詳細的記錄了mysql在Linux下的安裝方法,英文好的同鞋能夠直接的查看
三、mysql默認的安裝目錄就是在/usr/local/mysql,這就是上面爲何咱們要將其移動在/uer/local下的緣由;若是在你的機器上之前安裝有老闆本的mysql,須要先將它的文件刪除,同時注意刪除老闆本的etc/my.cnf文件和/etc/mysql目錄,這兩個文件控制的是mysql的一些配置屬性。
sql
四、先要建立的一個名爲mysql的用戶組和用戶,來承載mysql數據庫的運行,使用以下命令: 數據庫
建立用戶組: ubuntu
在建立的用戶組中建立一個用戶:
1 |
sudo useradd -r -g mysql mysql |
這裏使用sudo命令是確保以root權限執行此命令,若是你登入本機的用戶是root用戶,則直接的使用groupadd和useradd命令
題外話:對應刪除用戶組及用戶的命令是groupdel和userdel。 安全
五、接着進入mysql目錄,修改mysql目錄的擁有者,爲mysql用戶: socket
這裏的點「.」表明的就是當前目錄,選項-R表示遞歸當前目錄及其子目錄
六、安裝mysql,執行命令: 網站
1 |
sudo scripts/mysql_install_db --user=mysql |
正確輸出: spa
01 |
root@tianbaoxing-virtual-machine:/usr/local/mysql# sudo scripts/mysql_install_db --user=mysql |
02 |
Installing MySQL system tables... |
04 |
Filling help tables... |
07 |
To start mysqld at boot time you have to copy |
08 |
support-files/mysql.server to the right place for your system |
10 |
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! |
11 |
To do so, start the server, then issue the following commands: |
13 |
./bin/mysqladmin -u root password 'new-password' |
14 |
./bin/mysqladmin -u root -h tianbaoxing-virtual-machine password 'new-password' |
16 |
Alternatively you can run: |
17 |
./bin/mysql_secure_installation |
19 |
which will also give you the option of removing the test |
20 |
databases and anonymous user created by default. This is |
21 |
strongly recommended for production servers. |
23 |
See the manual for more instructions. |
25 |
You can start the MySQL daemon with: |
26 |
cd . ; ./bin/mysqld_safe & |
28 |
You can test the MySQL daemon with mysql-test-run.pl |
29 |
cd ./mysql-test ; perl mysql-test-run.pl |
31 |
Please report any problems with the ./bin/mysqlbug script! |
注意:在Ubuntu 12.04下安裝mysql 5.5.34版本執行此命令時,會提示以下錯誤的信息: .net
1 |
root@tianbaoxing-virtual-machine:/usr/local/mysql# sudo scripts/mysql_install_db --user=mysql |
2 |
Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: |
3 |
libaio.so.1: cannot open shared object file: No such file or directory |
這說明還要安裝一個libaio的依賴庫,執行以下命令:
安裝共享庫libaio1。在終端輸入: sudo apt-get install libaio1
7/執行完上面的命令後,其實就已經完成了mysql的安裝,但爲了數據庫的安全,能夠將mysql目錄的擁有者改成root用戶,並將生成的系統依賴數據賦給mysql用戶,執行以下命令:
8/安裝好mysql後,就能夠試着啓動它,使用以下命令:
1 |
sudo ./support-files/mysql.server start |
一樣重啓和中止,只須要將上面命令的start改成restart或stop。
9/啓動完mysql後,使用「./bin/mysql」命令來進入mysql數據庫的控制檯,執行SQL命令
結果:
01 |
mysql> show databases; |
02 |
+--------------------+ |
04 |
+--------------------+ |
05 |
| information_schema | |
07 |
| performance_schema | |
09 |
+--------------------+ |
10 |
4 rows in set (0.01 sec) |
十、修改mysql密碼:
數據庫初始密碼是空的,設置密碼:(注意因爲數據庫初始密碼是空,因此Enter password:這一步時直接按回車建)
1 |
sudo ./bin/mysqladmin -u root -p password 'root' |
3 |
root@tianbaoxing-virtual-machine:/usr/local/mysql# |
設置這個密碼命令,費了好大的力氣,最後仍是查看安裝mysql後輸出的提示命令。
11/查看mysql版本:
guoyachao@ubuntu:/usr/local/mysql$ ./bin/mysqladmin -u root -p version Enter password:
./bin/mysqladmin Ver 8.42 Distrib 5.5.34, for linux2.6 on i686
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Server version 5.5.34
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /tmp/mysql.sock
Uptime: 13 min 38 sec
Threads: 1 Questions: 10 Slow queries: 0 Opens: 33 Flush tables: 1 Open tables: 26 Queries per second avg: 0.012
文章借鑑於:http://www.linuxidc.com/Linux/2012-06/62458.htm;
來源於 http://my.oschina.net/winHerson/blog/112309